具有输入的字段取决于其他输入
have fields of an input depend other inputs
我有 2 个输入,比如 A 和 B。
我希望 B 的 "value" 字段取决于用户为 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。但是一直没有得到解答(虽然评论肯定有帮助)
谢谢
您应该使用 uiOutput
和 renderUI
生成取决于输入的小部件:
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")
})
}
)
我有 2 个输入,比如 A 和 B。
我希望 B 的 "value" 字段取决于用户为 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。但是一直没有得到解答(虽然评论肯定有帮助)
谢谢
您应该使用 uiOutput
和 renderUI
生成取决于输入的小部件:
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")
})
}
)