1

我想知道如何设置pickerInput()要显示的标题 - "Please select a month"- 当默认选择值时。

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)
4

1 回答 1

2

“请选择月份”将显示在选择器本身中,但仅在初始执行时显示。同样在初始执行时,选择所有月份。当观察到选择器的任何事件时,选择器本身将显示选定的值。

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)
于 2021-04-16T00:37:06.860 回答