The Shiny documentation mentions that for selectInput()
:
selected
The value (or, if none was supplied, the title) of the naviga
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)
})
}
)