Description Usage Arguments Details Value Examples
A Shiny binary toggle input.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
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 |
false |
character, right label for |
color |
active state color. |
text_color |
color of left and right value label text. |
width |
The width of the input, e.g. |
session |
The session object passed to function given to shinyServer. |
This input returns TRUE
or FALSE
similar to
shiny::checkboxInput
.
HTML element that can be added to a UI definition.
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")
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.