sa_toggle: Toggle input

Description Usage Arguments Details Value Examples

View source: R/toggle.R

Description

A Shiny binary toggle input.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
sa_toggle(
  inputId,
  label,
  value = FALSE,
  true = "Yes",
  false = "No",
  color = "blue",
  text_color = "black",
  width = NULL
)

update_sa_toggle(
  session,
  inputId,
  label = NULL,
  value = NULL,
  true = NULL,
  false = NULL
)

Arguments

inputId

The id of the input object.

label

The label to set for the input object.

value

logical, default toggle state.

true

character, left label for TRUE state.

false

character, right label for FALSE state.

color

active state color.

text_color

color of left and right value label text.

width

The width of the input, e.g. '400px', or '100%'; see shiny::validateCssUnit.

session

The session object passed to function given to shinyServer.

Details

This input returns TRUE or FALSE similar to shiny::checkboxInput.

Value

HTML element that can be added to a UI definition.

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
if (interactive()) {
library(shiny)

ui <- function(request) {
fluidPage(
  use_access(),
  fluidRow(bookmarkButton()),
  fluidRow(
    column(3,
      actionButton("btn1", "Set to TRUE"),
      actionButton("btn2", "Change label"),
      sa_toggle(
        "toggle1", "Show text A", FALSE, "On", "Off",
        "firebrick", "white", 200
      ),
      sa_toggle(
        "toggle2", "Show text B", TRUE, "On", "Off",
        "yellowgreen", "black"
      )
    ),
    column(9, textOutput("txt1"), textOutput("txt2"))
  )
)
}

server <- function(input, output, session) {
  output$txt1 <- renderText(paste("Toggle input 1 is set to", input$toggle1))
  output$txt2 <- renderText(paste("Toggle input 2 is set to", input$toggle2))
  observeEvent(input$btn1, {
    update_sa_toggle(session, "toggle1", value = TRUE)
  })
  observeEvent(input$btn2, {
    update_sa_toggle(session, "toggle1", label = "Show text A 2",
                     true = "Yes", false = "No")
  })
}

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

}

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