根据ShinyApp

时间:2016-09-20 09:24:24

标签: r radio-button shiny

我有一个我正在分析的时间序列。我想使用ShinyApp创建一个仪表板,用户可以选择使用ARIMA og Holt Winter来进行预测。

我不知道如何接收单选按钮的输入并将它们带到不同的步骤。

我尝试了以下操作,但收到以下错误:

Error in source("~/ShinyApp/TEST.R") : ~/ShinyApp/TEST.R:31:18: unexpected '=' 30: 31: if (input$n3 =

library(shiny)
require(forecast)

name = c (2,4,3,8,6,12,4,16)
name <- ts(name, frequency=12, start=c(2007,1))

ui <- fluidPage(

  numericInput(inputId = "n2", "Size of training set", value = 12),

  radioButtons(inputId = "n3", "Forecast type",  c("Holt Winter's" = "HW", "ARIMA" = "arima")),

  plotOutput(outputId = "graph"), 

  plotOutput(outputId = "graph2")

)




server <- function(input, output) { 

  output$graph <- renderPlot({

        plot(name, type = "l")  } ) }


  output$graph2 <- renderPlot( {

    if (input$n3 = "HW") { 

      fit <- ets (name, model = "ZAZ", damped=TRUE)

     plot(forecast(fit,level=c(80,80,99), h = input$n2), main = "Forecast, HW")
    }

    if (input$n3 = "arima") { 


      fit <- auto.arima (name)

      plot(forecast(fit, 12), main = "Forecast, ARIMA")

    } ) } 



shinyApp(ui = ui, server = server)

1 个答案:

答案 0 :(得分:1)

您使用了def self.get_next_some_seq DB.fetch("select nextval('some_seq')").first[:nextval] end 运算符而不是=运算符if if语句(==用于分配,=用于检查相等性)

此外,可读性非常差,你周围都有括号。重构后它起作用:

==