Interactively change the selectInput choices

僤鯓⒐⒋嵵緔 提交于 2019-11-28 04:22:26

You need to make the UI reactive. I haven't tested this (miss data for it too) but should work I think. In server.R add:

output$selectUI <- renderUI({ 
selectInput("partnerName", "Select your choice", searchResult()[,1] ),
})

And in ui.R replace the selectInput with:

htmlOutput("selectUI")

In Shiny version 0.8 (where I have tested it), in server.R add the following:

shinyServer(function(input, output, session) {

  observe({
    # This will change the value of input$partnerName to searchResult()[,1]
    updateTextInput(session, "partnerName", 
                    label = "Select your choice", 
                    value = searchResult()[,1])
  })

})

Now the function within shinyServer has additional argument session.

You can skip the label if you don't need to change it.

You don't need to change anything in ui.R.

Green Demon

Reply from Rstudio's JC:

Sure, just use a textInput for the search string, and use renderUI/uiOutput to make a dynamic selectInput. Then the rest of your code can depend on the selectInput's value. (Make sure to check for NULL or whatever when reading the selectInput value, because it will start out with no value.)

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