sa_radio: Radio buttons input

Description Usage Arguments Value Examples

View source: R/radio.R

Description

A Shiny radio buttons input.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
sa_radio(
  inputId,
  label,
  choices = NULL,
  selected = NULL,
  inline = FALSE,
  width = NULL,
  choiceNames = NULL,
  choiceValues = NULL
)

update_sa_radio(
  session,
  inputId,
  label = NULL,
  choices = NULL,
  selected = NULL,
  inline = FALSE
)

Arguments

inputId

The id of the input object.

label

The label to set for the input object.

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). If this argument is provided, then choiceNames and choiceValues must not be provided, and vice-versa. The values should be strings; other types (such as logicals and numbers) will be coerced to strings.

selected

The values that should be initially selected, if any.

inline

if TRUE, ncol is ignored.

width

not in use

choiceNames, choiceValues

See shiny::radioButtons. Vector of names and values, must have same length.

session

The session object passed to function given to shinyServer.

Value

A list of HTML elements that can be added to a UI definition.#' @export

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
if (interactive()) {
library(shiny)

ui <- function(request) {
fluidPage(
  use_access(),
  fluidRow(bookmarkButton()),
  fluidRow(
    column(3,
      actionButton("btn1", "Reset radio 1 to 'am'"),
      radioButtons(
        "radio1", "Shiny1 - Choose a variable:",
        list("Cylinders" = "cyl", "Transmission" = "am", "Gears" = "gear"),
        width = "1000px"),
      tableOutput("data1")
    ),
    column(3,
      radioButtons(
        "radio2", "Shiny2 (inline) - Choose a variable:",
        list("Cylinders" = "cyl", "Transmission" = "am", "Gears" = "gear"),
        inline = TRUE),
      tableOutput("data2")
    ),
    column(3,
      actionButton("btn3", "Reset radio 3 to 'am'"),
      sa_radio(
        "radio3", "SA1 - Choose a variable:",
        c("Cylinders" = "cyl", "Transmission" = "am", "Gears" = "gear", "A" = "a", "B" = "b"),
        selected = "am"),
      tableOutput("data3")
    ),
    column(3,
    actionButton("btn4", "Reset radio 4 to 'gear'"),
      sa_radio(
        "radio4", "SA2 (inline) - Choose a variable:",
        selected = "cyl",
        choiceNames = c("Cylinders", "Transmission", "Gears"),
        choiceValues = c("cyl", "am", "gear"), inline = TRUE),
      tableOutput("data4")
    )
  )
)
}

server <- function(input, output, session) {
  output$data1 <- renderTable({
    mtcars[, c("mpg", input$radio1), drop = FALSE]
  }, rownames = TRUE)

  output$data2 <- renderTable({
    mtcars[, c("mpg", input$radio2), drop = FALSE]
  }, rownames = TRUE)
  output$data3 <- renderTable({
    mtcars[, c("mpg", input$radio3), drop = FALSE]
  }, rownames = TRUE)

  output$data4 <- renderTable({
    mtcars[, c("mpg", input$radio4), drop = FALSE]
  }, rownames = TRUE)

  observeEvent(input$btn1, {
    updateRadioButtons(session, "radio1", selected = "am")
  })
  observeEvent(input$btn3, {
    update_sa_radio(session, "radio3", selected = "am")
  })
  observeEvent(input$btn4, {
    update_sa_radio(session, "radio4", selected = "gear")
  })
}

shinyApp(ui, server, enableBookmarking = "url")

}

leonawicz/shinyaccess documentation built on Aug. 15, 2020, 12:40 a.m.