简体   繁体   English

自动绘图闪亮,选择输入不起作用

[英]Autoplot in shiny with Select Input not working

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.我正在尝试创建一个自动绘图,它将根据用户选择的变量显示一个绘图,但它只是显示为一条直线,即使 y 轴上的名称确实根据用户选择的内容而变化。 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)

You are calling ?autoplot.tbl_ts and that method requires an expressio for the variable, not a string which is what input$select returns.您正在调用?autoplot.tbl_ts并且该方法需要变量的表达式,而不是input$select返回的字符串。 Instead you can use the .data pronoun相反,您可以使用.data代词

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM