'Set the maximum number of choices made by pickerInput()

Im trying to limit the max number of choices made by pickerInput() to two in shiny app but I cannot make it work.

library(shiny)
library(shinydashboard)
library(plotly)
library(shinyWidgets)
header <- dashboardHeader()

sidebar <- dashboardSidebar(
  
  
  fluidRow(column(12,
                  pickerInput(
                    inputId = "iss",
                    label = "Issue", 
                    choices = colnames(mtcars),
                    multiple = T,
                    options =  list("max-options-group" = 2)
                  )           
  ))
  
)

body <- dashboardBody(fluidPage(
  
  
  )
  
)


ui <- dashboardPage(title = 'Search', header, sidebar, body)


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


Solution 1:[1]

Try this

columns <- as.list(names(mtcars))
type <- as.list(1:ncol(mtcars))
header <- dashboardHeader()

sidebar <- dashboardSidebar(

  fluidRow(column(12,
                  pickerInput(
                    inputId = "iss",
                    label = "Issue",
                    choices = list(Columns = columns,
                                   Type = type),
                    selected = list(columns[[1]],type[[1]]),
                    multiple = T,
                    inline=TRUE,
                    options =  list("max-options-group" = 1, `style` = "btn-info")
                  )
  ))

)

body <- dashboardBody(fluidPage())

ui <- dashboardPage(title = 'Search', header, sidebar, body)

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1