Force no default selection in selectInput()

前端 未结 6 1150
别跟我提以往
别跟我提以往 2021-02-01 02:17

The Shiny documentation mentions that for selectInput():

selected The value (or, if none was supplied, the title) of the naviga

6条回答
  •  隐瞒了意图╮
    2021-02-01 02:49

    A workaround would be to use updateSelectInput. The point here is that you set your selected = argument to length(your_vector_with_choices).

    You can create a reactiveValues if you want your selectInput to be updated at the very beginning (in that case only observed at program start).

    library(shiny)
    
    shinyApp(
      ui = fluidPage(
        selectInput("state", "Choose a state:", NULL),
        textOutput("result")
      ),
      
      server = function(input, output, session) {
        values <- reactiveValues(start = NULL)
        
        observe({
          choiceList <- list(`East Coast` = list("NY", "NJ", "CT"),
                             `West Coast` = list("WA", "OR", "CA"),
                             `Midwest` = list("MN", "WI", "IA"))
          updateSelectInput(session, "state", choices = choiceList, selected = choiceList[length(choiceList)])
        })
        
        output$result <- renderText({
          paste("You chose", input$state)
        })
      }
    )
    

提交回复
热议问题