This input operates like a shiny::radioButtons() or shiny::checkboxGroupInput() input.

buttonGroup(inputId, choices, choice_labels = names(choices) %||%
  choices, btn_class = "btn-default", btn_icon = NULL,
  btn_extra = NULL, selected = NULL, multiple = FALSE, ...)

buttonGroupDemo(display.mode = c("showcase", "normal", "auto"))

updateButtonGroupValue(inputId, values = NULL,
  session = shiny::getDefaultReactiveDomain())

Arguments

inputId

The input id

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.

btn_class

A single class applied to each individual button, or a vector of button classes for each button (must be same length as choices). For more information see https://getbootstrap.com/docs/3.3/css/#buttons. The default button class is, appropriately, "btn-default". Be sure to include this or a similar button style class if you modify btn_class.

btn_icon

An single icon name or a vector of icon names (must be the same length as choices) to be applied to the buttons. See shiny::icon() for more information.

btn_extra

A list or list of lists of additional attributes to be added to the buttons. If the list does not contain sublists (i.e. depth 1), then the same attributes are applied to all of the buttons. Otherwise, the list of attributes should match the buttons generated from choices.

For example

buttonGroup(
  inputId = "special_group", choices = c("one", "two"),
  btn_extra = list(
    list(alt = "Button One"),
    list(alt = "Button Two")
  )
)
selected

The buttons, by button value, that should be activated.

multiple

By default, only a single button may be toggled at a time. If multiple is TRUE, then buttonGroup() returns a character vector of the selected button values.

...

Passed to htmltools::div()

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.

values

The choices (not choice labels) that should be activated. Set to NULL to deactivate all buttons.

session

The session object passed to function given to shinyServer.

Value

The value returned by the input to the Shiny server is either NULL when no buttons are selected or a character vector containing the values from choices corresponding to the active buttons.

Functions

  • buttonGroupDemo: Example app demonstrating usage of the buttonGroup input.

  • updateButtonGroupValue: Set active buttons to the choices in values, which must match the values in choices provided to buttonGroup().

Examples

if (interactive()) { library(shiny) ui <- fluidPage( titlePanel("shinyThings Toggle Button Groups"), fluidRow( column( width = 6, tags$h4("Buttons with icons"), shinyThings::buttonGroup( inputId = "button_icon", choices = c("left", "center", "justify", "right"), btn_icon = paste0("align-", c("left", "center", "justify", "right")), multiple = FALSE ), tags$p(), verbatimTextOutput("chosen_icon") ), column( width = 6, tags$h4("Buttons with HTML"), shinyThings::buttonGroup( inputId = "button_html", choices = c("bold", "italic", "underline", "strikethrough"), choice_labels = list( HTML("<strong>B</strong>"), HTML("<i>I</i>"), HTML("<span style='text-decoration: underline'>U</span>"), HTML("<del>S</del>") ), multiple = TRUE ), tags$p(), verbatimTextOutput("chosen_html") ) ) ) server <- function(input, output, session) { output$chosen_icon <- renderPrint(input$button_icon) output$chosen_html <- renderPrint(input$button_html) } shinyApp(ui, server) }