2016-02-12 99 views
0

我有一個問題來編碼一個應用程序,是預測庫的情節,並沒有顯示出來。閃亮的預測情節

- 我想用滑塊範圍輸入這個繪圖,所以你可以設置置信度。用「級別」表示。

- 不要太注意複選框。

下面的代碼:

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

你不必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) 

+0

非常感謝。如果它允許我在幾分鐘內打勾綠色。 –

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") 
) 
+0

你有兩個帶''百分數'的ID –

+1

謝謝,我沒有注意到它也在'ui'的sliderInput部分內。 – Marta