0
votes

Im having a problem to code an app that is a plot with forecast library and is not showing up.

-I want this plot with a slider Range input so you can set the confidence rate. Indicated in "level".

-Dont pay too much attention to the checkboxes.

Here the code:

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

2 Answers

2
votes

You dont have 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
votes

Your ui should look like this (you forgot about plotOutput("percent") part, so R does not know that it should draw something):

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