Debian Codegraph @

man/updateSelectInput.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/update-input.R
3 \name{updateSelectInput}
4 \alias{updateSelectInput}
5 \alias{updateSelectizeInput}
6 \alias{updateVarSelectInput}
7 \alias{updateVarSelectizeInput}
8 \title{Change the value of a select input on the client}
9 \usage{
10 updateSelectInput(
11 session = getDefaultReactiveDomain(),
12 inputId,
13 label = NULL,
14 choices = NULL,
15 selected = NULL
16 )
17
18 updateSelectizeInput(
19 session = getDefaultReactiveDomain(),
20 inputId,
21 label = NULL,
22 choices = NULL,
23 selected = NULL,
24 options = list(),
25 server = FALSE
26 )
27
28 updateVarSelectInput(
29 session = getDefaultReactiveDomain(),
30 inputId,
31 label = NULL,
32 data = NULL,
33 selected = NULL
34 )
35
36 updateVarSelectizeInput(
37 session = getDefaultReactiveDomain(),
38 inputId,
39 label = NULL,
40 data = NULL,
41 selected = NULL,
42 options = list(),
43 server = FALSE
44 )
45 }
46 \arguments{
47 \item{session}{The \code{session} object passed to function given to
48 \code{shinyServer}. Default is \code{getDefaultReactiveDomain()}.}
49
50 \item{inputId}{The id of the input object.}
51
52 \item{label}{The label to set for the input object.}
53
54 \item{choices}{List of values to select from. If elements of the list are
55 named, then that name --- rather than the value --- is displayed to the
56 user. It's also possible to group related inputs by providing a named list
57 whose elements are (either named or unnamed) lists, vectors, or factors. In
58 this case, the outermost names will be used as the group labels (leveraging
59 the \verb{<optgroup>} HTML tag) for the elements in the respective sublist. See
60 the example section for a small demo of this feature.}
61
62 \item{selected}{The initially selected value (or multiple values if \code{multiple = TRUE}). If not specified then defaults to the first value for
63 single-select lists and no values for multiple select lists.}
64
65 \item{options}{A list of options. See the documentation of \pkg{selectize.js}(\url{https://selectize.dev/docs/usage})
66 for possible options (character option values inside \code{\link[base:AsIs]{base::I()}} will
67 be treated as literal JavaScript code; see \code{\link[=renderDataTable]{renderDataTable()}}
68 for details).}
69
70 \item{server}{whether to store \code{choices} on the server side, and load
71 the select options dynamically on searching, instead of writing all
72 \code{choices} into the page at once (i.e., only use the client-side
73 version of \pkg{selectize.js})}
74
75 \item{data}{A data frame. Used to retrieve the column names as choices for a \code{\link[=selectInput]{selectInput()}}}
76 }
77 \description{
78 Change the value of a select input on the client
79 }
80 \details{
81 The input updater functions send a message to the client, telling it to
82 change the settings of an input object. The messages are collected and sent
83 after all the observers (including outputs) have finished running.
84
85 The syntax of these functions is similar to the functions that created the
86 inputs in the first place. For example, \code{\link{numericInput}()} and
87 \code{updateNumericInput()} take a similar set of arguments.
88
89 Any arguments with NULL values will be ignored; they will not result in any
90 changes to the input object on the client.
91
92 For \code{\link{radioButtons}()}, \code{\link{checkboxGroupInput}()} and
93 \code{\link{selectInput}()}, the set of choices can be cleared by using
94 \code{choices=character(0)}. Similarly, for these inputs, the selected item
95 can be cleared by using \code{selected=character(0)}.
96 }
97 \examples{
98 ## Only run examples in interactive R sessions
99 if (interactive()) {
100
101 ui <- fluidPage(
102 p("The checkbox group controls the select input"),
103 checkboxGroupInput("inCheckboxGroup", "Input checkbox",
104 c("Item A", "Item B", "Item C")),
105 selectInput("inSelect", "Select input",
106 c("Item A", "Item B", "Item C"))
107 )
108
109 server <- function(input, output, session) {
110 observe({
111 x <- input$inCheckboxGroup
112
113 # Can use character(0) to remove all choices
114 if (is.null(x))
115 x <- character(0)
116
117 # Can also set the label and select items
118 updateSelectInput(session, "inSelect",
119 label = paste("Select input label", length(x)),
120 choices = x,
121 selected = tail(x, 1)
122 )
123 })
124 }
125
126 shinyApp(ui, server)
127 }
128 }
129 \seealso{
130 \code{\link[=selectInput]{selectInput()}} \code{\link[=varSelectInput]{varSelectInput()}}
131 }