% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/input-selectpicker.R
\name{pickerInput}
\alias{pickerInput}
\title{Select Picker Input Control}
\usage{
pickerInput(
  inputId,
  label = NULL,
  choices,
  selected = NULL,
  multiple = FALSE,
  options = list(),
  choicesOpt = NULL,
  width = NULL,
  inline = FALSE,
  stateInput = TRUE,
  autocomplete = FALSE
)
}
\arguments{
\item{inputId}{The \code{input} slot that will be used to access the value.}

\item{label}{Display label for the control, or \code{NULL} for no label.}

\item{choices}{List of values to select from. If elements of the
list are named then that name rather than the value is displayed to the user.}

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

\item{multiple}{Is selection of multiple items allowed?}

\item{options}{List of options, see \link{pickerOptions} for all available options.
To limit the number of selection possible, see example below.}

\item{choicesOpt}{A \code{list()} of options for individual choices in the dropdown menu,
each element of the \code{list} should the same length as \code{choices}. You can use the following options :
\itemize{
\item \code{disabled}: logical vector indicating if the choice can be selected or not.
\item \code{style}: CSS styles applied to the choice tag
\item \code{class}: CSS class added to the choice tag
\item \code{icon}: vector of icon names to display before choices (to use \code{icon("arrow-right")}, you have to use \code{fa-arrow-right} and \code{pickerOptions(iconBase = "fas")})
\item \code{subtext} add a text after the choice
\item \code{content}: replace entire choice with custom content (like raw HTML)
\item \code{tokens}: add tokens associated with choices used in search results.
}}

\item{width}{The width of the input : 'auto', 'fit', '100px', '75\%'.}

\item{inline}{Display picker inline, to have label and menu on same line use \code{width = "fit"}.}

\item{stateInput}{Activate or deactivate the special input value \verb{input$<inputId>_open} to know if the menu is opened or not, see details.}

\item{autocomplete}{Sets the initial state of the autocomplete property.}
}
\value{
A select control that can be added to a UI definition.
}
\description{
An alternative to \code{\link[shiny:selectInput]{shiny::selectInput()}} with plenty of options to customize it.
}
\note{
State of the picker (open or close) is accessible server-side through the input value:
\code{input$<inputId>_open}, which can be \code{TRUE} (opened) or \code{FALSE} (closed).
}
\examples{
## Only run examples in interactive R sessions
if (interactive()) {

# You can run the gallery to see other examples
shinyWidgetsGallery()


# Basic usage
library("shiny")
library(shinyWidgets)

ui <- fluidPage(
  pickerInput(
    inputId = "somevalue",
    label = "A label",
    choices = c("a", "b")
  ),
  verbatimTextOutput("value")
)

server <- function(input, output) {
  output$value <- renderPrint(input$somevalue)
}

shinyApp(ui, server)

}

### Add actions box for selecting ----
### deselecting all options

if (interactive()) {

  library(shiny)
  library(shinyWidgets)

  ui <- fluidPage(
    tags$h2("Select / Deselect all"),
    pickerInput(
      inputId = "p1",
      label = "Select all option",
      choices = rownames(mtcars),
      multiple = TRUE,
      options = list(`actions-box` = TRUE)
    ),
    verbatimTextOutput("r1"),
    br(),
    pickerInput(
      inputId = "p2",
      label = "Select all option / custom text",
      choices = rownames(mtcars),
      multiple = TRUE,
      options = list(
        `actions-box` = TRUE,
        `deselect-all-text` = "None...",
        `select-all-text` = "Yeah, all !",
        `none-selected-text` = "zero"
      )
    ),
    verbatimTextOutput("r2")
  )

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

    output$r1 <- renderPrint(input$p1)
    output$r2 <- renderPrint(input$p2)

  }

  shinyApp(ui = ui, server = server)

}

### Customize the values displayed in the box ----

if (interactive()) {

  library(shiny)
  library(shinyWidgets)

  ui <- fluidPage(
    br(),
    pickerInput(
      inputId = "p1",
      label = "Default",
      multiple = TRUE,
      choices = rownames(mtcars),
      selected = rownames(mtcars)[1:5]
    ),
    br(),
    pickerInput(
      inputId = "p1b",
      label = "Default with | separator",
      multiple = TRUE,
      choices = rownames(mtcars),
      selected = rownames(mtcars)[1:5],
      options = list(`multiple-separator` = " | ")
    ),
    br(),
    pickerInput(
      inputId = "p2",
      label = "Static",
      multiple = TRUE,
      choices = rownames(mtcars),
      selected = rownames(mtcars)[1:5],
      options = list(`selected-text-format`= "static",
                     title = "Won't change")
    ),
    br(),
    pickerInput(
      inputId = "p3",
      label = "Count",
      multiple = TRUE,
      choices = rownames(mtcars),
      selected = rownames(mtcars)[1:5],
      options = list(`selected-text-format`= "count")
    ),
    br(),
    pickerInput(
      inputId = "p3",
      label = "Customize count",
      multiple = TRUE,
      choices = rownames(mtcars),
      selected = rownames(mtcars)[1:5],
      options = list(
        `selected-text-format`= "count",
        `count-selected-text` = "{0} models choosed (on a total of {1})"
      )
    )
  )

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

  }

  shinyApp(ui = ui, server = server)

}

### Limit the number of selections ----

if (interactive()) {

  library(shiny)
  library(shinyWidgets)

  ui <- fluidPage(
    pickerInput(
      inputId = "groups",
      label = "Select one from each group below:",
      choices = list(
        Group1 = c("1", "2", "3", "4"),
        Group2 = c("A", "B", "C", "D")
      ),
      multiple = TRUE,
      options =  list("max-options-group" = 1)
    ),
    verbatimTextOutput(outputId = "res_grp"),
    pickerInput(
      inputId = "groups_2",
      label = "Select two from each group below:",
      choices = list(
        Group1 = c("1", "2", "3", "4"),
        Group2 = c("A", "B", "C", "D")
      ),
      multiple = TRUE,
      options =  list("max-options-group" = 2)
    ),
    verbatimTextOutput(outputId = "res_grp_2"),
    pickerInput(
      inputId = "classic",
      label = "Select max two option below:",
      choices = c("A", "B", "C", "D"),
      multiple = TRUE,
      options =  list(
        "max-options" = 2,
        "max-options-text" = "No more!"
      )
    ),
    verbatimTextOutput(outputId = "res_classic")
  )

  server <- function(input, output) {

    output$res_grp <- renderPrint(input$groups)
    output$res_grp_2 <- renderPrint(input$groups_2)
    output$res_classic <- renderPrint(input$classic)

  }

  shinyApp(ui, server)

}
}
\references{
SnapAppointments and contributors. "The jQuery plugin that brings
select elements into the 21st century with intuitive multiselection,
searching, and much more. Now with Bootstrap 4 support".
\url{https://github.com/snapappointments/bootstrap-select/}
}
\seealso{
\link{updatePickerInput} to update value server-side. \code{\link[=virtualSelectInput]{virtualSelectInput()}} for an alternative.
}
