问题
I have following basic code with shiny:
library(quantmod); library(shiny);
ui <- fluidPage(
textInput("Symbol","Assign_Symbol","GOOG"),
dateRangeInput("Date","Assing_Date", start = Sys.Date() - 20, end = Sys.Date()),
plotOutput("Chart")
)
server <- function(input, output) {
envSymbol <- new.env()
Sym <- "Sym"
envSymbol[[Sym]] <- reactive({
as.xts(getSymbols(input$Symbol, auto.assign = FALSE))
})
output$Chart <- renderPlot({
chartSeries(
envSymbol[[Sym]],
theme = chartTheme("white"),
type = "line",
subset = paste(input$Date, collapse = "::")
)
})
}
shinyApp(ui, server)
The window comes up with symbol and date as expected, but in the chart section I always get Error: chartSeries requires an xtsible object
I don't know shiny and this is from code samples online. I have found longer more complicated samples, but I still get the same xtsible object error.
Can somebody tell me what I am missing?
回答1:
The reactive expression envSymbol[[Sym]]
is technically a function. So to call it you must call it with parenthesis ( envSymbol[[Sym]]()
) when calling chartSeries
. For more detailed information have a look at this video. (should start at around 1h03m)
来源:https://stackoverflow.com/questions/57699454/shiny-app-error-chartseries-requires-an-xtsible-object