A Not-So-Basic Shiny App

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.


Article content
The Closing tab


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.


Article content
The Open-High-Low-Close tab


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.


Article content
The Yesterday tab


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?

Like
Reply

To view or add a comment, sign in

More articles by Marc Hendel

  • Tangling with Lists as Fields in Power BI

    I recently had to work with a string of values presented in a list within a field in Power BI. I quickly determined…

  • Combo Graph - Python Makes It Easy

    I am brushing up on my Python skills for my new position at Principal Financial Group and I have an improved method for…

  • Small Multiples to the Rescue

    I wanted to continue some coding exercises from storytelling with data so I worked on the most recent exercise, 3.10.

    1 Comment
  • Combo Charts

    The November challenge from storytelling with data asks to create a "combo chart" - a chart with more than one display…

  • UFOs and Bubble Maps

    Sometimes we end up with too much data. It is important to feel comfortable telling a story with some of the available…

    2 Comments
  • R Shiny App - Maps

    My next Shiny app demo allows me to show off my mapping skills. I located data from the US Census Bureau's American…

  • You Can't Fatten a Cow by Weighing It

    You may have heard the phrase in the title before. If not, you should know that despite its farm reference, it applies…

    2 Comments
  • A Basic Shiny App Revisited

    As with most tasks in R, there is typically more than one way to accomplish a goal. In my post earlier today titled A…

  • A Basic Shiny App

    Shiny is an app creation package that can be used in R or Python. Apps can be published online so anyone can use them…

  • Hi, Bob!

    Two important web-related tasks that every data scientist should be familiar with: pulling data from the web and screen…

Others also viewed

Explore content categories