I am new to Shiny and finished the Shiny tutorial over here: http://shiny.rstudio.com/tutorial/
In lesson 6, the tutorial shows us how to create an App where you input the stock symbol and date range to see its chart on the main panel.
I am trying to go a bit further by changing the App to one that takes 2 stock symbols and draws them on the same chart comparing them over time (overlapping on the same chart).
I've modified server.R to be:
library(quantmod)
shinyServer(function(input, output) {
dataInput <- reactive({
getSymbols(c(input$symb1, input$symb2), src = "yahoo",
from = input$dates[1],
to = input$dates[2],
auto.assign = TRUE)
})
output$plot <- renderPlot({
chartSeries(dataInput(), theme = chartTheme("white"),
type = "line", log.scale = input$log, TA = NULL)
})
})
and my uiR to be:
library(shiny)
shinyUI(fluidPage(
titlePanel("StockComp"),
sidebarLayout(
sidebarPanel(
helpText("Select two stocks and a time frame to compare.
Information will be collected from yahoo finance."),
textInput("symb1", "1st Stock Symbol", "GOOG"),
textInput("symb2", "2nd Stock Symbol", "AAPL"),
dateRangeInput("dates",
"Date range",
start = "2012-01-01",
end = as.character(Sys.Date())),
actionButton("get", "Compare Stocks"),
br(),
br(),
checkboxInput("log", "Plot y axis on log scale",
value = FALSE)
),
mainPanel(plotOutput("plot"))
)
))
I am getting:
Error in try.xts(x, error = "chartSeries requires an xtsible object") : chartSeries requires an xtsible object
I have tried to convert the dataInput to XTS, but XTS and reactive seems to be causing a lot of issues for me with my limited understanding of whats going on.