【问题标题】:How to use updateSelectInput in flexdashboard?如何在 flexdashboard 中使用 updateSelectInput?
【发布时间】:2018-02-01 00:47:52
【问题描述】:

我想根据另一个输入框更改输入框的值。

R Shiny 有一个可用的方法:updateSelectInput。但我不确定如何在 flexdashboard 中使用它。

【问题讨论】:

  • 你不能,flexdashboards 不是响应式的。
  • 谢谢@mtoto。也许我应该用 Shiny 重写我的代码。

标签: r shiny flexdashboard


【解决方案1】:

这已经很晚了,但也很有可能。

如果这是你的第一个selectInput()

raw_data <- mpg

selectInput(
  "manufacturer",
  label = "Select manufacturer",
  choices = c("All", sort(unique(raw_data$manufacturer)))
)

您可以尝试这两种方法中的任何一种。这个整体代码更少:

renderUI({

  df <-
    raw_data %>%
    filter(
      manufacturer == input$manufacturer |
        input$manufacturer == "All"
    )

  selectInput(
    "model",
    label = "Select model",
    choices = c("All", sort(unique(df$model)))
  )

})

observeEvent()。我认为这可以节省性能,因为它只查看一个输入,但差别不大。

selectInput(
    "model",
    label = "Select model",
    choices = c("All", sort(unique(raw_data$model)))
  )


observeEvent(input$manufacturer, {
  df <-
    raw_data %>%
    filter(
      manufacturer == input$manufacturer |
        input$manufacturer == "All"
    )

  updateSelectInput(
    session = session,
    inputId = "model",
    choices = c("All", sort(unique(df$model)))
  )
})

【讨论】:

    猜你喜欢
    • 2018-08-23
    • 2017-07-18
    • 1970-01-01
    • 2021-10-27
    • 2021-04-26
    • 2017-06-16
    • 2017-02-11
    • 2018-10-23
    • 2018-11-15
    相关资源
    最近更新 更多