Shiny app Error chartSeries requires an xtsible object?

≯℡__Kan透↙ 提交于 2021-01-29 13:03:16

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!