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())
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 |
btn_class | A single class applied to each individual button, or a
vector of button classes for each button (must be same length as
|
btn_icon | An single icon name or a vector of icon names (must be the
same length as |
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 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 |
... | Passed to |
display.mode | The mode in which to display the application. If set to
the value |
values | The |
session | The |
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.
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()
.
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) }