stocksApp

JP Van Steerteghem
January 28th, 2018

stocksApp introduction

The stocksApp app looks up stock prices by ticker symbol and displays the results as a line chart. The app lets you -Select a stock to examine -Pick a range of dates to review

By default, stocksApp displays the CSCO ticker (Cisco Systems Inc). To look up a different stock, type in a stock symbol that Google finance will recognize.

stocksApp design

stocksApp is a shiny application that uses R’s quantmod package

stocksApp relies heavily on two functions from the quantmod package:

  • It uses getSymbols to download financial data straight into R from websites like Google finance.
  • It uses chartSeries to display prices in an attractive chart.

The stocksApp app uses two input widgets.

  • text input
  • date range selector, created with dateRangeInput

ui.R code

library(shiny)
library(quantmod)
shinyUI(fluidPage(
  titlePanel("Stock performance over a specified date range"),
  sidebarPanel(
    helpText("Replace the default Ticker Symbol and enter the Ticker Symbol and the date range you are interested in"),
    textInput("symb", "Symbol", "CSCO"),
    dateRangeInput("dates", 
                   "Date range",
                   start = "2013-01-01", 
                   end = as.character(Sys.Date()))
  ),
  mainPanel(
    h3("Stock performance & trading volume "),
    plotOutput("plot"))
)
)

<!–html_preserve–>

Stock performance over a specified date range

Replace the default Ticker Symbol and enter the Ticker Symbol and the date range you are interested in
to

Stock performance & trading volume

<!–/html_preserve–>

server.R code

library(shiny)
library(quantmod)
server <- function(input, output) {
  dataInput <- reactive({  
    getSymbols(input$symb, src = "google",
               from = input$dates[1],
               to = input$dates[2],
               auto.assign = FALSE)
  })
  output$plot <- renderPlot({
    chartSeries(dataInput(), theme = chartTheme("white"),
                type = "line")
  }) 
}

stocksApp output

alt text