"季节性"对于输入变量,R包不能很好用

时间:2016-02-22 13:07:18

标签: r shiny

我一直在使用优秀的季节性'用于X11 / X13 ARIMA分析的R包,但在series()调用中使用input$参数时,seas()调用会看到一些不稳定的行为。

fit_x <- seas(x = tv, x11 = "", forecast.maxlead = as.numeric(input$months),
forecast.probability = as.numeric(input$interval))
# R executes the above statement ok
x_fc <- series(fit_x, "forecast.forecasts")
# this doesn't work

fit_x <- seas(x = tv, x11 = "", forecast.maxlead = 12, forecast.probability = 0.90)
# R executes the above statement ok
x_fc <- series(fit_x, "forecast.forecasts")
# this does work

堆栈跟踪是:

Warning: Error in seas: object 'input' not found
Stack trace (innermost first):
    68: seas
    67: eval
    66: eval
    65: reeval
    64: series
    63: observeEventHandler [/Users/koen/Shiny R/Apps/html/server.R#93]
     1: runApp

任何见解?谢谢!

1 个答案:

答案 0 :(得分:0)

修改我的原始答案。我没有意识到你在谈论一个闪亮的输入元素(我想我应该阅读标题......)

问题是series函数会重新评估对海洋的调用,因此它会在input$months语句中使用eval,这将无效。

解决问题的两种简单方法:

  1. 通过强制seas保存预测输出来避免重新评估:

    fit_x <- seas(x = AirPassengers, x11 = "", 
    forecast.maxlead = as.numeric(input$months),
    forecast.probability = as.numeric(input$interval), 
    forecast.save = "fct") 
    

    由于seas输出中已经存在预测,因此不需要重新评估,并且不应发生错误。除了解决问题,这也会使执行速度加倍。

  2. 将输入保存在中间变量中(好的,有点明显):

    a <- as.numeric(input$months)
    b <- as.numeric(input$interval)
    fit_x <- seas(x = AirPassengers, x11 = "", forecast.maxlead = a, forecast.probability = b)