2017-04-13 70 views
0

我有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。但它沒有得到回答(儘管評論肯定有幫助)。

謝謝

回答

0

您應該使用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") 
    }) 
    } 
) 
相關問題