Learn R Programming

shinyBS (version 0.20)

Button Customizations: Shiny Button Customizations

Description

Functions for setting and changing the style, size, and state of various buttons in a shiny app.

Usage

bsButton(inputId, label, value, style = NULL, size = NULL, block = FALSE, 
         disabled = FALSE)
bsActionButton(inputId, label, style = NULL, size = NULL, block = FALSE, 
               disabled = FALSE)
bsToggleButton(inputId, label, value, style = NULL, size = NULL, block = FALSE,
               disabled = FALSE)
bsButtonGroup(inputId, ..., label, toggle = "checkbox", style, size, 
              value = NULL, disabled = FALSE, block = FALSE, vertical = FALSE)
updateButton(session, id, label = NULL, value = NULL, style = NULL, size = NULL, 
             block = NULL, disabled = NULL)
updateButtonGroup(session, id, toggle = NULL, style = NULL, size = NULL, 
                  disabled = NULL, value = NULL)

Arguments

session
The session object passed to function given to shinyServer
inputId
Id to assign to the button or button group
id
The id of the button/button group you want to update
...
bsButton() objects to be added to the button group
label
For buttons, the text to appear inside the button. For button groups, an optional label that will appear above the button group
toggle
The type of toggle behaviour the button group should have (See Details)
style
The bootstrap style the button(s) should take (See Details)
size
The bootstrap size the button(s) should take (See Details)
block
Should the button or button group be a block level element? (i.e., should it span the width of its parent element)
vertical
Should the button group's buttons have a vertical orientation?
value
The value of the button/button group (See Details)
disabled
Should the button(s) be disabled? logical

Details

bsActionButton() creates an action button that behaves just as a standard shiny action button does. It has the added functionality of being able to changed its style and size. It can also be disabled/enabled. toggle can take a value of either radio or checkbox. radio will allow only one button in the button group to be selected at a time. checkbox will allow any number of buttons to be selected at a time. style can be any of the styles described in the Twitter Bootstrap 2.3.2 documentation. Acceptable values are currently: primary, info, success, warning, danger, inverse, or link. Additionally, when calling one of the update functions, style can be set to default to return to the default button style. size can be any of the sizes described in the Twitter Bootstrap 2.3.2 documentation. Accepatble values are currently: large, small, or mini. Additionally, when calling one of the update functions, style can be set to default to return to the default size. For toggle buttons, value can be TRUE or FALSE and corresponds to whether the button is currently 'clicked.' For bsButton, value is used to set the value that will be returned by containing bsButtonGroup object when the button is clicked. For button groups, value is used to set the current value to be returned by the group and should correspond to values assigned to buttons contained in the button group. vertical and block for button groups are experimental. They do not work well together and may not work under all browsers.

References

http://getbootstrap.com/2.3.2/components.html{Alerts for Twitter Bootstrap 2.3.2}

Examples

Run this code
# Create an action button, toggle button and a button group 
  # with three buttons with default styling in ui.R
  bsActionButton("ab1", label = "bsActionButton"), 
  bsToggleButton("tb1", label = "bsToggleButton"), tags$p(), 
  bsButtonGroup("btngrp1", label = "bsButtonGroup", toggle = "radio", value = "right", 
                bsButton("btn1", label = "Left", value = "left"), 
                bsButton("btn2", label = "Middle", value = "middle"), 
                bsButton("btn3", label = "Right", value = "right")
                )
                
  # Update the previous buttons/button group to be small 
  # and of primary style in server.R
  updateButton(session, "ab1", style = "primary", size = "small") 
  updateButton(session, "tb1", style = "primary", size = "small") 
  updateButtonGroup(session, "btngrp1", style = "primary", size = "small")

Run the code above in your browser using DataLab