0

I'm trying to create an autoplot that will show a plot based on what variable the user selects, but it just shows up as a straight line even though the name on the y axis does change depening on what the user chooses. Here is a basic version of the code:

library(shiny)
library(fpp3)
ui <- fluidPage(
  selectInput("select", "Choose variable", choices = names(aus_production)),
  plotOutput("plot")
)

server <- function(input,output){
  
  output$plot <- renderPlot({
   aus_production %>% autoplot(input$select) 
  })
  
}

shinyApp(ui = ui,server = server)
An Bha
  • 1
  • That doesn't look like any `autoplot` syntax that I know of, though it is a generic function. What exactly do you want to plot to look like? What should be on the x and y axis? – MrFlick Oct 22 '21 at 00:07
  • It's a time series autoplot, so on the x-axis, it shows Quarter (Q1 1960, Q1 1980, Q1 2000, etc) and on the y-axis, it's one of the columns from aus_production, so it could be a time series showing Beer, Tobacco, Bricks, Cement, Electricity, or Gas `aus_production %>% autoplot(Gas)` would show Gas production – An Bha Oct 22 '21 at 02:27

1 Answers1

0

You are calling ?autoplot.tbl_ts and that method requires an expressio for the variable, not a string which is what input$select returns. Instead you can use the .data pronoun

server <- function(input,output){
  
  output$plot <- renderPlot({
   aus_production %>% autoplot(.data[[input$select]]) 
  })
  
}
MrFlick
  • 195,160
  • 17
  • 277
  • 295