have fields of an input depend other inputs

心不动则不痛 提交于 2019-12-12 06:48:54

问题


I have 2 inputs, say A and B.

I would like the "value" field of B to depend on the value inputted by the user for A.

I.e., my suggestion for B depends on what I learnt in A.

The following code does not work. How should I fix it please?

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"}
  }
)

This issue is also raised here. But it has not been answered (although the comments are definitely helpful).

thank you


回答1:


You should use uiOutput and renderUI to generate widgets which depends of the input :

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")
    })
  }
)


来源:https://stackoverflow.com/questions/43389314/have-fields-of-an-input-depend-other-inputs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!