input_switch | R Documentation |
Create an on-off style switch control for specifying logical values.
input_switch(id, label, value = FALSE, width = NULL)
update_switch(id, label = NULL, value = NULL, session = get_current_session())
toggle_switch(id, value = NULL, session = get_current_session())
id |
An input id. |
label |
A label for the switch. |
value |
Whether or not the switch should be checked by default. |
width |
Any valid CSS unit (e.g.,
|
session |
a shiny session object (the default should almost always be used). |
Returns a UI element for a switch input control. The server value
received for the input corresponding to id
will be a logical
(TRUE
/FALSE
) value.
Other input controls:
input_dark_mode()
library(shiny)
library(bslib)
ui <- page_fixed(
title = "Keyboard Settings",
h2("Keyboard Settings"),
input_switch("auto_capitalization", "Auto-Capitalization", TRUE),
input_switch("auto_correction", "Auto-Correction", TRUE),
input_switch("check_spelling", "Check Spelling", TRUE),
input_switch("smart_punctuation", "Smart Punctuation"),
h2("Preview"),
verbatimTextOutput("preview")
)
server <- function(input, output, session) {
output$preview <- renderPrint({
list(
auto_capitalization = input$auto_capitalization,
auto_correction = input$auto_correction,
check_spelling = input$check_spelling,
smart_punctuation = input$smart_punctuation
)
})
}
shinyApp(ui, server)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.