【问题标题】:have fields of an input depend other inputs有一个输入的字段依赖于其他输入
【发布时间】:2017-09-09 09:38:29
【问题描述】:

我有 2 个输入,比如 A 和 B。

我希望 B 的“值”字段取决于用户为 A 输入的值。

也就是说,我对 B 的建议取决于我在 A 中学到的知识。

以下代码不起作用。请问应该怎么解决?

shinyApp(
  ui = fluidPage(
    textInput("A", "Enter a string"),
    textInput("B", "Enter another string", value = "Second"),
    textOutput("curval")
  ),
  server = function(input, output) {
    if (input$A == "foo"){input$B$value <- "bar"}
  }
)

这个问题也被提出here。但是还没有得到回答(尽管 cmets 肯定有帮助)。

谢谢

【问题讨论】:

    标签: r shiny shiny-server


    【解决方案1】:

    您应该使用uiOutputrenderUI 来生成依赖于输入的小部件:

    shinyApp(
      ui = fluidPage(
        textInput("A", "Enter a string"),
        uiOutput("B_ui"),
        textOutput("curval")
      ),
      server = function(input, output) {
        output$B_ui <- renderUI({
          if (input$A=="foo") textInput("B","Enter another string",value="bar")
          else textInput("B","Enter another string",value="Second")
        })
      }
    )
    

    【讨论】:

      猜你喜欢
      • 2022-08-05
      • 1970-01-01
      • 2016-06-18
      • 1970-01-01
      • 2023-02-09
      • 2019-01-19
      • 2021-05-23
      • 2019-07-20
      • 1970-01-01
      相关资源
      最近更新 更多