Debian Codegraph @

man/radioButtons.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/input-radiobuttons.R
3 \name{radioButtons}
4 \alias{radioButtons}
5 \title{Create radio buttons}
6 \usage{
7 radioButtons(
8 inputId,
9 label,
10 choices = NULL,
11 selected = NULL,
12 inline = FALSE,
13 width = NULL,
14 choiceNames = NULL,
15 choiceValues = NULL
16 )
17 }
18 \arguments{
19 \item{inputId}{The \code{input} slot that will be used to access the value.}
20
21 \item{label}{Display label for the control, or \code{NULL} for no label.}
22
23 \item{choices}{List of values to select from (if elements of the list are
24 named then that name rather than the value is displayed to the user). If
25 this argument is provided, then \code{choiceNames} and \code{choiceValues} must not
26 be provided, and vice-versa. The values should be strings; other types
27 (such as logicals and numbers) will be coerced to strings.}
28
29 \item{selected}{The initially selected value. If not specified, then it
30 defaults to the first item in \code{choices}. To start with no items selected,
31 use \code{character(0)}.}
32
33 \item{inline}{If \code{TRUE}, render the choices inline (i.e. horizontally)}
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{choiceNames, choiceValues}{List of names and values, respectively, that
39 are displayed to the user in the app and correspond to the each choice (for
40 this reason, \code{choiceNames} and \code{choiceValues} must have the same length).
41 If either of these arguments is provided, then the other \emph{must} be provided
42 and \code{choices} \emph{must not} be provided. The advantage of using both of these
43 over a named list for \code{choices} is that \code{choiceNames} allows any type of UI
44 object to be passed through (tag objects, icons, HTML code, ...), instead
45 of just simple text. See Examples.}
46 }
47 \value{
48 A set of radio buttons that can be added to a UI definition.
49 }
50 \description{
51 Create a set of radio buttons used to select an item from a list.
52 }
53 \details{
54 If you need to represent a "None selected" state, it's possible to default
55 the radio buttons to have no options selected by using \code{selected = character(0)}. However, this is not recommended, as it gives the user no way
56 to return to that state once they've made a selection. Instead, consider
57 having the first of your choices be \code{c("None selected" = "")}.
58 }
59 \section{Server value}{
60
61
62 A character string containing the value of the selected button.
63 }
64
65 \examples{
66 ## Only run examples in interactive R sessions
67 if (interactive()) {
68
69 ui <- fluidPage(
70 radioButtons("dist", "Distribution type:",
71 c("Normal" = "norm",
72 "Uniform" = "unif",
73 "Log-normal" = "lnorm",
74 "Exponential" = "exp")),
75 plotOutput("distPlot")
76 )
77
78 server <- function(input, output) {
79 output$distPlot <- renderPlot({
80 dist <- switch(input$dist,
81 norm = rnorm,
82 unif = runif,
83 lnorm = rlnorm,
84 exp = rexp,
85 rnorm)
86
87 hist(dist(500))
88 })
89 }
90
91 shinyApp(ui, server)
92
93 ui <- fluidPage(
94 radioButtons("rb", "Choose one:",
95 choiceNames = list(
96 icon("calendar"),
97 HTML("<p style='color:red;'>Red Text</p>"),
98 "Normal text"
99 ),
100 choiceValues = list(
101 "icon", "html", "text"
102 )),
103 textOutput("txt")
104 )
105
106 server <- function(input, output) {
107 output$txt <- renderText({
108 paste("You chose", input$rb)
109 })
110 }
111
112 shinyApp(ui, server)
113 }
114
115 }
116 \seealso{
117 \code{\link[=updateRadioButtons]{updateRadioButtons()}}
118
119 Other input elements:
120 \code{\link{actionButton}()},
121 \code{\link{checkboxGroupInput}()},
122 \code{\link{checkboxInput}()},
123 \code{\link{dateInput}()},
124 \code{\link{dateRangeInput}()},
125 \code{\link{fileInput}()},
126 \code{\link{numericInput}()},
127 \code{\link{passwordInput}()},
128 \code{\link{selectInput}()},
129 \code{\link{sliderInput}()},
130 \code{\link{submitButton}()},
131 \code{\link{textAreaInput}()},
132 \code{\link{textInput}()},
133 \code{\link{varSelectInput}()}
134 }
135 \concept{input elements}