This input creates a radio switch that works like shiny::radioButtons()
with the appearance of a button
radioSwitchButtons(inputId, label = NULL, choices, choice_labels = names(choices) %||% choices, selected = choices[1], selected_background = NULL, selected_color = NULL, not_selected_background = NULL, not_selected_color = NULL) updateRadioSwitchButtons(inputId, selected = NULL, session = shiny::getDefaultReactiveDomain()) radioSwitchButtons_default_style(selected_background = NULL, selected_color = NULL, not_selected_background = NULL, not_selected_color = NULL) radioSwitchButtonsDemo(display.mode = c("showcase", "normal", "auto"))
inputId | The input id |
---|---|
label | The text to appear above the buttons (set to |
choices | A vector of choices for the button group. The names will be used for button labels and the value are returned by the input. If an unnamed vector is provided, the button labels and values returned will be the same. |
choice_labels | A list of labels for the choices that can be arbitrary
HTML if wrapped in |
selected | The value that should be active initially. |
selected_background | Background color of the label when selected. Can
be set globally via |
selected_color | Text color of the label text when selected. Can be set
globally via |
not_selected_background | Background color of the label when not
selected. Can be set globally via |
not_selected_color | Text color of the label text when not selected. Can
be set globally via |
session | The |
display.mode | The mode in which to display the application. If set to
the value |
updateRadioSwitchButtons
: Update the selected value of the radio switch
button input associated with inputId
.
radioSwitchButtons_default_style
: Set default values for the radio switch
buttons.
radioSwitchButtonsDemo
: Example app demonstrating the usage of the
radioSwitchButtons input.
Adapted from CSS code by Mike Hemberger described in https://thestizmedia.com/radio-buttons-as-toggle-buttons-with-css/.
if (interactive()) { library(shiny) library(shinyThings) ui <- fluidPage( inputPanel( radioSwitchButtons( inputId = "other", label = "Yes or No?", choices = c("Yes" = "yes", "No" = "no", "Maybe?" = "maybe"), selected_background = "#eb1455" ), radioSwitchButtons( inputId = "small", label = "Style", choices = c("plain", "bold", "italic"), choice_labels = list( tags$span(style = "font-weight: normal", "P"), tags$strong("B"), tags$em("I") ) ) ), verbatimTextOutput("values") ) server <- function(input, output, session) { output$values <- renderPrint({ str(list( moreThanTwo = input$other, style = input$small )) }) } shinyApp(ui, server) }