Force no default selection in selectInput()

前端 未结 6 1250
别跟我提以往
别跟我提以往 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:39

    @Yihui Xie's answer requires selectInput(..., selectize = TRUE). If you want selectize = FALSE, you can still achieve a similar effect as follows.

    This is not documented:

    selected The initially selected value (or multiple values if multiple = TRUE). If not specified then defaults to the first value for single-select lists and no values for multiple select lists.

    But for single-select lists if you can use selectize = FALSE, size = 4 (any non-NULL size would work), then you can set selected = FALSE to force no default selection.

    library(shiny)
    
    # Define UI for application that draws a histogram
    ui <- fluidPage(
          mainPanel(
             uiOutput("Choose_Molecule")
          )
    )
    
    # Define server logic required to draw a histogram
    server <- function(input, output) {
    
        # First UI input (Service column) filter clientData 
        output$Choose_Molecule <- renderUI({
            selectInput("molecule",
                        "Select Molecule:",
                        choices = rownames(mtcars),
                        selected = FALSE,
                        multiple = FALSE
                        , selectize = FALSE, size = 4  ##needed for `selected = FALSE` to work
            )
        })
    
    }
    
    # Run the application 
    shinyApp(ui = ui, server = server)
    

提交回复
热议问题