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"))

Arguments

inputId

The input id

label

The text to appear above the buttons (set to NULL for no label.)

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 HTML(). Set to "" or NULL for no label.

selected

The value that should be active initially.

selected_background

Background color of the label when selected. Can be set globally via radioSwitchButtons_default_style(). Default value is "#007BFF".

selected_color

Text color of the label text when selected. Can be set globally via radioSwitchButtons_default_style(). Default value is "#FFFFFF".

not_selected_background

Background color of the label when not selected. Can be set globally via radioSwitchButtons_default_style(). Default value is "#FFFFFF".

not_selected_color

Text color of the label text when not selected. Can be set globally via radioSwitchButtons_default_style(). Default value is "#AAAAAA".

session

The session object passed to function given to shinyServer.

display.mode

The mode in which to display the application. If set to the value "showcase", shows application code and metadata from a DESCRIPTION file in the application directory alongside the application. If set to "normal", displays the application normally. Defaults to "auto", which displays the application in the mode given in its DESCRIPTION file, if any.

Functions

  • 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.

References

Adapted from CSS code by Mike Hemberger described in https://thestizmedia.com/radio-buttons-as-toggle-buttons-with-css/.

Examples

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) }