| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/input-select.R |
| 3 |
\name{varSelectInput} |
| 4 |
\alias{varSelectInput} |
| 5 |
\alias{varSelectizeInput} |
| 6 |
\title{Select variables from a data frame} |
| 7 |
\usage{ |
| 8 |
varSelectInput( |
| 9 |
inputId, |
| 10 |
label, |
| 11 |
data, |
| 12 |
selected = NULL, |
| 13 |
multiple = FALSE, |
| 14 |
selectize = TRUE, |
| 15 |
width = NULL, |
| 16 |
size = NULL |
| 17 |
) |
| 18 |
|
| 19 |
varSelectizeInput(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{data}{A data frame. Used to retrieve the column names as choices for a \code{\link[=selectInput]{selectInput()}}} |
| 27 |
|
| 28 |
\item{selected}{The initially selected value (or multiple values if \code{multiple = TRUE}). If not specified then defaults to the first value for |
| 29 |
single-select lists and no values for multiple select lists.} |
| 30 |
|
| 31 |
\item{multiple}{Is selection of multiple items allowed?} |
| 32 |
|
| 33 |
\item{selectize}{Whether to use \pkg{selectize.js} or not.} |
| 34 |
|
| 35 |
\item{width}{The width of the input, e.g. \code{'400px'}, or \code{'100\%'}; |
| 36 |
see \code{\link[=validateCssUnit]{validateCssUnit()}}.} |
| 37 |
|
| 38 |
\item{size}{Number of items to show in the selection box; a larger number |
| 39 |
will result in a taller box. Not compatible with \code{selectize=TRUE}. |
| 40 |
Normally, when \code{multiple=FALSE}, a select input will be a drop-down list, |
| 41 |
but when \code{size} is set, it will be a box instead.} |
| 42 |
|
| 43 |
\item{...}{Arguments passed to \code{varSelectInput()}.} |
| 44 |
|
| 45 |
\item{options}{A list of options. See the documentation of \pkg{selectize.js}(\url{https://selectize.dev/docs/usage}) |
| 46 |
for possible options (character option values inside \code{\link[base:AsIs]{base::I()}} will |
| 47 |
be treated as literal JavaScript code; see \code{\link[=renderDataTable]{renderDataTable()}} |
| 48 |
for details).} |
| 49 |
} |
| 50 |
\value{ |
| 51 |
A variable select list control that can be added to a UI definition. |
| 52 |
} |
| 53 |
\description{ |
| 54 |
Create a select list that can be used to choose a single or multiple items |
| 55 |
from the column names of a data frame. |
| 56 |
} |
| 57 |
\details{ |
| 58 |
By default, \code{varSelectInput()} and \code{selectizeInput()} use the |
| 59 |
JavaScript library \pkg{selectize.js} |
| 60 |
(\url{https://selectize.dev/}) to instead of the basic |
| 61 |
select input element. To use the standard HTML select input element, use |
| 62 |
\code{selectInput()} with \code{selectize=FALSE}. |
| 63 |
} |
| 64 |
\note{ |
| 65 |
The variable selectize input created from \code{varSelectizeInput()} allows |
| 66 |
deletion of the selected option even in a single select input, which will |
| 67 |
return an empty string as its value. This is the default behavior of |
| 68 |
\pkg{selectize.js}. However, the selectize input created from |
| 69 |
\code{selectInput(..., selectize = TRUE)} will ignore the empty string |
| 70 |
value when it is a single choice input and the empty string is not in the |
| 71 |
\code{choices} argument. This is to keep compatibility with |
| 72 |
\code{selectInput(..., selectize = FALSE)}. |
| 73 |
} |
| 74 |
\section{Server value}{ |
| 75 |
|
| 76 |
The resulting server \code{input} value will be returned as: |
| 77 |
\itemize{ |
| 78 |
\item A symbol if \code{multiple = FALSE}. The \code{input} value should be |
| 79 |
used with rlang's \code{\link[rlang:injection-operator]{rlang::!!()}}. For example, |
| 80 |
\code{ggplot2::aes(!!input$variable)}. |
| 81 |
\item A list of symbols if \code{multiple = TRUE}. The \code{input} value |
| 82 |
should be used with rlang's \code{\link[rlang:splice-operator]{rlang::!!!()}} to expand |
| 83 |
the symbol list as individual arguments. For example, |
| 84 |
\code{dplyr::select(mtcars, !!!input$variabls)} which is |
| 85 |
equivalent to \code{dplyr::select(mtcars, !!input$variabls[[1]], !!input$variabls[[2]], ..., !!input$variabls[[length(input$variabls)]])}. |
| 86 |
} |
| 87 |
} |
| 88 |
|
| 89 |
\examples{ |
| 90 |
|
| 91 |
## Only run examples in interactive R sessions |
| 92 |
if (interactive()) { |
| 93 |
|
| 94 |
library(ggplot2) |
| 95 |
|
| 96 |
# single selection |
| 97 |
shinyApp( |
| 98 |
ui = fluidPage( |
| 99 |
varSelectInput("variable", "Variable:", mtcars), |
| 100 |
plotOutput("data") |
| 101 |
), |
| 102 |
server = function(input, output) { |
| 103 |
output$data <- renderPlot({ |
| 104 |
ggplot(mtcars, aes(!!input$variable)) + geom_histogram() |
| 105 |
}) |
| 106 |
} |
| 107 |
) |
| 108 |
|
| 109 |
|
| 110 |
# multiple selections |
| 111 |
\dontrun{ |
| 112 |
shinyApp( |
| 113 |
ui = fluidPage( |
| 114 |
varSelectInput("variables", "Variable:", mtcars, multiple = TRUE), |
| 115 |
tableOutput("data") |
| 116 |
), |
| 117 |
server = function(input, output) { |
| 118 |
output$data <- renderTable({ |
| 119 |
if (length(input$variables) == 0) return(mtcars) |
| 120 |
mtcars \%>\% dplyr::select(!!!input$variables) |
| 121 |
}, rownames = TRUE) |
| 122 |
} |
| 123 |
)} |
| 124 |
|
| 125 |
} |
| 126 |
} |
| 127 |
\seealso{ |
| 128 |
\code{\link[=updateSelectInput]{updateSelectInput()}} |
| 129 |
|
| 130 |
Other input elements: |
| 131 |
\code{\link{actionButton}()}, |
| 132 |
\code{\link{checkboxGroupInput}()}, |
| 133 |
\code{\link{checkboxInput}()}, |
| 134 |
\code{\link{dateInput}()}, |
| 135 |
\code{\link{dateRangeInput}()}, |
| 136 |
\code{\link{fileInput}()}, |
| 137 |
\code{\link{numericInput}()}, |
| 138 |
\code{\link{passwordInput}()}, |
| 139 |
\code{\link{radioButtons}()}, |
| 140 |
\code{\link{selectInput}()}, |
| 141 |
\code{\link{sliderInput}()}, |
| 142 |
\code{\link{submitButton}()}, |
| 143 |
\code{\link{textAreaInput}()}, |
| 144 |
\code{\link{textInput}()} |
| 145 |
} |
| 146 |
\concept{input elements} |