| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/input-select.R |
| 3 |
\name{selectInput} |
| 4 |
\alias{selectInput} |
| 5 |
\alias{selectizeInput} |
| 6 |
\title{Create a select list input control} |
| 7 |
\usage{ |
| 8 |
selectInput( |
| 9 |
inputId, |
| 10 |
label, |
| 11 |
choices, |
| 12 |
selected = NULL, |
| 13 |
multiple = FALSE, |
| 14 |
selectize = TRUE, |
| 15 |
width = NULL, |
| 16 |
size = NULL |
| 17 |
) |
| 18 |
|
| 19 |
selectizeInput(inputId, ..., options = NULL, width = NULL) |
| 20 |
} |
| 21 |
\arguments{ |
| 22 |
\item{inputId}{The \code{input} slot that will be used to access the value.} |
| 23 |
|
| 24 |
\item{label}{Display label for the control, or \code{NULL} for no label.} |
| 25 |
|
| 26 |
\item{choices}{List of values to select from. If elements of the list are |
| 27 |
named, then that name --- rather than the value --- is displayed to the |
| 28 |
user. It's also possible to group related inputs by providing a named list |
| 29 |
whose elements are (either named or unnamed) lists, vectors, or factors. In |
| 30 |
this case, the outermost names will be used as the group labels (leveraging |
| 31 |
the \verb{<optgroup>} HTML tag) for the elements in the respective sublist. See |
| 32 |
the example section for a small demo of this feature.} |
| 33 |
|
| 34 |
\item{selected}{The initially selected value (or multiple values if \code{multiple = TRUE}). If not specified then defaults to the first value for |
| 35 |
single-select lists and no values for multiple select lists.} |
| 36 |
|
| 37 |
\item{multiple}{Is selection of multiple items allowed?} |
| 38 |
|
| 39 |
\item{selectize}{Whether to use \pkg{selectize.js} or not.} |
| 40 |
|
| 41 |
\item{width}{The width of the input, e.g. \code{'400px'}, or \code{'100\%'}; |
| 42 |
see \code{\link[=validateCssUnit]{validateCssUnit()}}.} |
| 43 |
|
| 44 |
\item{size}{Number of items to show in the selection box; a larger number |
| 45 |
will result in a taller box. Not compatible with \code{selectize=TRUE}. |
| 46 |
Normally, when \code{multiple=FALSE}, a select input will be a drop-down list, |
| 47 |
but when \code{size} is set, it will be a box instead.} |
| 48 |
|
| 49 |
\item{...}{Arguments passed to \code{selectInput()}.} |
| 50 |
|
| 51 |
\item{options}{A list of options. See the documentation of \pkg{selectize.js}(\url{https://selectize.dev/docs/usage}) |
| 52 |
for possible options (character option values inside \code{\link[base:AsIs]{base::I()}} will |
| 53 |
be treated as literal JavaScript code; see \code{\link[=renderDataTable]{renderDataTable()}} |
| 54 |
for details).} |
| 55 |
} |
| 56 |
\value{ |
| 57 |
A select list control that can be added to a UI definition. |
| 58 |
} |
| 59 |
\description{ |
| 60 |
Create a select list that can be used to choose a single or multiple items |
| 61 |
from a list of values. |
| 62 |
} |
| 63 |
\details{ |
| 64 |
By default, \code{selectInput()} and \code{selectizeInput()} use the JavaScript library |
| 65 |
\pkg{selectize.js} (\url{https://selectize.dev/}) instead of |
| 66 |
the basic select input element. To use the standard HTML select input |
| 67 |
element, use \code{selectInput()} with \code{selectize=FALSE}. |
| 68 |
|
| 69 |
In selectize mode, if the first element in \code{choices} has a value of \code{""}, its |
| 70 |
name will be treated as a placeholder prompt. For example: |
| 71 |
\code{selectInput("letter", "Letter", c("Choose one" = "", LETTERS))} |
| 72 |
|
| 73 |
\strong{Performance note:} \code{selectInput()} and \code{selectizeInput()} can slow down |
| 74 |
significantly when thousands of choices are used; with legacy browsers like |
| 75 |
Internet Explorer, the user interface may hang for many seconds. For large |
| 76 |
numbers of choices, Shiny offers a "server-side selectize" option that |
| 77 |
massively improves performance and efficiency; see |
| 78 |
\href{https://shiny.rstudio.com/articles/selectize.html}{this selectize article} |
| 79 |
on the Shiny Dev Center for details. |
| 80 |
} |
| 81 |
\note{ |
| 82 |
The selectize input created from \code{selectizeInput()} allows |
| 83 |
deletion of the selected option even in a single select input, which will |
| 84 |
return an empty string as its value. This is the default behavior of |
| 85 |
\pkg{selectize.js}. However, the selectize input created from |
| 86 |
\code{selectInput(..., selectize = TRUE)} will ignore the empty string |
| 87 |
value when it is a single choice input and the empty string is not in the |
| 88 |
\code{choices} argument. This is to keep compatibility with |
| 89 |
\code{selectInput(..., selectize = FALSE)}. |
| 90 |
} |
| 91 |
\section{Server value}{ |
| 92 |
A vector of character strings, usually of length |
| 93 |
1, with the value of the selected items. When \code{multiple=TRUE} and |
| 94 |
nothing is selected, this value will be \code{NULL}. |
| 95 |
} |
| 96 |
|
| 97 |
\examples{ |
| 98 |
## Only run examples in interactive R sessions |
| 99 |
if (interactive()) { |
| 100 |
|
| 101 |
# basic example |
| 102 |
shinyApp( |
| 103 |
ui = fluidPage( |
| 104 |
selectInput("variable", "Variable:", |
| 105 |
c("Cylinders" = "cyl", |
| 106 |
"Transmission" = "am", |
| 107 |
"Gears" = "gear")), |
| 108 |
tableOutput("data") |
| 109 |
), |
| 110 |
server = function(input, output) { |
| 111 |
output$data <- renderTable({ |
| 112 |
mtcars[, c("mpg", input$variable), drop = FALSE] |
| 113 |
}, rownames = TRUE) |
| 114 |
} |
| 115 |
) |
| 116 |
|
| 117 |
# demoing group support in the `choices` arg |
| 118 |
shinyApp( |
| 119 |
ui = fluidPage( |
| 120 |
selectInput("state", "Choose a state:", |
| 121 |
list(`East Coast` = list("NY", "NJ", "CT"), |
| 122 |
`West Coast` = list("WA", "OR", "CA"), |
| 123 |
`Midwest` = list("MN", "WI", "IA")) |
| 124 |
), |
| 125 |
textOutput("result") |
| 126 |
), |
| 127 |
server = function(input, output) { |
| 128 |
output$result <- renderText({ |
| 129 |
paste("You chose", input$state) |
| 130 |
}) |
| 131 |
} |
| 132 |
) |
| 133 |
} |
| 134 |
|
| 135 |
} |
| 136 |
\seealso{ |
| 137 |
\code{\link[=updateSelectInput]{updateSelectInput()}} \code{\link[=varSelectInput]{varSelectInput()}} |
| 138 |
|
| 139 |
Other input elements: |
| 140 |
\code{\link{actionButton}()}, |
| 141 |
\code{\link{checkboxGroupInput}()}, |
| 142 |
\code{\link{checkboxInput}()}, |
| 143 |
\code{\link{dateInput}()}, |
| 144 |
\code{\link{dateRangeInput}()}, |
| 145 |
\code{\link{fileInput}()}, |
| 146 |
\code{\link{numericInput}()}, |
| 147 |
\code{\link{passwordInput}()}, |
| 148 |
\code{\link{radioButtons}()}, |
| 149 |
\code{\link{sliderInput}()}, |
| 150 |
\code{\link{submitButton}()}, |
| 151 |
\code{\link{textAreaInput}()}, |
| 152 |
\code{\link{textInput}()}, |
| 153 |
\code{\link{varSelectInput}()} |
| 154 |
} |
| 155 |
\concept{input elements} |