JP Van Steerteghem
January 28th, 2018
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 is a shiny application that uses R’s quantmod package
stocksApp relies heavily on two functions from the quantmod package:
The stocksApp app uses two input widgets.
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–>
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")
})
}