闪亮的预测图

时间:2016-02-12 07:53:21

标签: r forecasting shiny

我有一个问题是编写一个带有预测库的图表并且没有显示的应用程序。

- 我希望此绘图带有滑块范围输入,以便您可以设置置信度。用“级别”表示。

- 不要过多关注复选框。

这里是代码:

library(shiny)

    ui <- fluidPage(


      (titlePanel("app | Forecast Models", windowTitle = 
                    "app")),


          #Range Input

          sliderInput(inputId = "range",
                      label = "Set Confidence Interval",
                      min = 0,max = 100, value = c(60,90),
                      step = NULL,
                      plotOutput(outputId = "percent")),

        #Checkbox input


        checkboxGroupInput(inputId = "checkbox", label = "Select Forecast",
                           choices = c("Trend","Level"),
                           plotOutput(outputId = "hist"), inline = T))




    #server.R

    library(forecast)
    timese <- ts(WWWusage, start= c(2008,1), end= c(2016,1), frequency=12)
    fit <- StructTS(timese,"trend")


    server <- function(input, output)  {

      output$percent <- renderPlot({
             plot(forecast(fit,

              #Confidence Interval %

              level = c(input$range)), sub= "Confidence Interval 70% ~ 90%
     or Determined by user", ylab= "Y Axis Variable",
     main=
       "Forecast Linear Structural Model @ Trend-Wise",
     ylim = c(0,400))
      })
    }





    shinyApp(ui = ui, server = server)

2 个答案:

答案 0 :(得分:2)

你没有mainPanel

rm(list = ls())
library(shiny)
library(forecast)
timese <- ts(WWWusage, start= c(2008,1), end= c(2016,1), frequency=12)
fit <- StructTS(timese,"trend")


ui <- fluidPage(
  (titlePanel("app | Forecast Models", windowTitle = "app")),
  #Range Input
  sliderInput(inputId = "range",
              label = "Set Confidence Interval",
              min = 0,max = 100, value = c(60,90)),

  #Checkbox input
  checkboxGroupInput(inputId = "checkbox", label = "Select Forecast",choices = c("Trend","Level"),plotOutput(outputId = "hist"), inline = T),
  mainPanel(plotOutput(outputId = "percent"))

  )

server <- function(input, output) {
  output$percent <- renderPlot({
    plot(forecast(fit, #Confidence Interval %
                  level = c(input$range)), sub= "Confidence Interval 70% ~ 90% or Determined by user", ylab= "Y Axis Variable",
         main= "Forecast Linear Structural Model @ Trend-Wise",ylim = c(0,400))
  })

}
shinyApp(ui, server) 

enter image description here

答案 1 :(得分:1)

你的ui应该是这样的(你忘记了plotOutput("percent")部分,所以R不知道它应该画一些东西):

ui <- fluidPage(


    titlePanel("app | Forecast Models", windowTitle = "app"),

    sliderInput(inputId = "range",
                label = "Set Confidence Interval",
                min = 0,max = 100, value = c(60,90),
                step = NULL),

   checkboxGroupInput(inputId = "checkbox", label = "Select Forecast",
                       choices = c("Trend","Level"),
                       plotOutput(outputId = "hist"), inline = T),

    plotOutput("percent")
)