2

I would like to know how I could set the title of a pickerInput() to be displayed -"Please select a month"- when values are selected by default.

library(shiny)
library(shinyWidgets)

ui <- fluidPage(
  pickerInput(
    inputId = "month",
    label = "Select a month",
    choices = month.name,
    selected = month.name,
    multiple = TRUE,
    options = pickerOptions(
      actionsBox = TRUE,
      title = "Please select a month",
      header = "This is a title"
    )
  )
)

server <- function(input, output, session) {
  
}

shinyApp(ui, server)
firmo23
  • 7,490
  • 2
  • 38
  • 114
  • The picker displays the selected values if there are some. And the title is a placeholder. So what do you expect to see? – Stéphane Laurent Apr 17 '21 at 12:25
  • "Please select a month" when I run the app for first time while all months are selected by default. I do not know if this is possible. – firmo23 Apr 17 '21 at 12:28

1 Answers1

2

"Please select a month" will display in the picker itself but only at initial execution. Also at initial execution, all months are selected. When any event is observed for the picker, the picker itself will then show the selected values.

library(shiny)
library(shinyWidgets)

ui <- fluidPage(
  pickerInput(
    inputId = "month",
    label = "Select a month",
    choices = month.name,
    selected = month.name,
    multiple = TRUE,
    options = pickerOptions(
      actionsBox = TRUE,
      title = "Please select a month",
      selectedTextFormat = 'static',
      header = "This is a title"
    )
  )
)

server <- function(input, output, session) {
  observeEvent(input$month, {
    updatePickerInput(session = session, inputId = "month",options = pickerOptions(selectedTextFormat = 'values'))
  }, ignoreInit = TRUE)
}  

shinyApp(ui, server)
John Girardot
  • 341
  • 2
  • 5