A Not-So-Basic Shiny App
My next Shiny app demo was created to show off some additional Shiny skills, including the use of tabs and dynamic graphs and text.
I selected three main stock indexes: the Dow Jones Industrial Average, the S & P 500 and the NASDAQ. Using the quantmod package in R, the code pulls daily open, high, low and close prices for each index from January 3, 1992 through the present day. This code can easily be modified to ask the user for any three stock symbols to customize it to their liking. But, that is for another day.
The app presents the user with a date range selector, using a calendar to select begin and end dates for the graphs displayed. The first tab (Closing Price) shows three line graphs of the closing price of each index with the area below the line to the x-axis shaded. Since the plotly package was used, rolling a cursor over the graph shows the date and closing price for each data point.
The second tab (Open-High-Low-Close) shows a chart with those four values for each date in the selected range. To make things easier to see, when the tab is selected, the date range automatically changes to the most recent calendar year. Making that happen utilizes the observe() function in R to make a reactive change to the start and end values of the date range selector.
Recommended by LinkedIn
The third tab (Yesterday) was created to show how to put dynamic text on a tab. The open and close values from the previous trading day (not always "yesterday" depending on when the app is used) are displayed, along with a calculated field with the change over the day; a green up arrow represents an increase in value and a red down arrow represents a decrease in value.
Check out the app in action here or, better yet, download the app.R code from GitHub and check out how it was built.
#R #shiny #stockprices #plotly #shinytabs #OHLCchart #datascientist
As always it was a good read but got a question can we use "one day before Today() or Sys.Date()" instead of "yesterday" so that the user get exactly which yesterday? Or it wont make much sense?