【问题标题】:Use selection from selectInput in a formula在公式中使用 selectInput 中的选择
【发布时间】:2021-03-14 08:08:37
【问题描述】:

我有这样的事情:

ui <- fluidPage(
  fluidRow(
    column(4,
           pickerInput("period", "Period", c("day", "week", "month"), 
                       options = list(`actions-box` = TRUE))))

我的输出(情节)需要根据这个输入中的选择而改变:

output$result <- renderPlotly({
    ggplot(data) +
      geom_bar(aes(x = paste(input$period)(birthday)))

换句话说,结果应该是day(birthday)week(birthday)month(birthday)。在这种情况下我应该怎么做?我的代码paste(input$period)(birthday) 不是正确的。

谢谢

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    你可以的

    output$result <- renderPlotly({
        fn <- switch(
          input$period,
          day = day,
          week = week,
          month = month
        )
        ggplot(data) +
          geom_bar(aes(x = fn(birthday)))
    })
    

    【讨论】:

    • 感谢@Stéphane。我有另一个问题。如果我想让 fn 为空怎么办?即在一种情况下:ggplot(data) + geom_bar(aes(x = (birthday)))
    猜你喜欢
    • 2023-03-26
    • 2020-04-19
    • 2019-01-19
    • 2019-11-20
    • 1970-01-01
    • 2017-04-22
    • 2018-04-25
    • 1970-01-01
    • 2021-01-22
    相关资源
    最近更新 更多