buttonGroup: A Bootstrap Button Group Input

Description Usage Arguments Value Functions Examples

View source: R/button-group.R

Description

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

Usage

1
2
3
4
5
6
7
8
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

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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)
}

gadenbuie/shinyThings documentation built on Nov. 24, 2019, 6:56 p.m.