Package 'reactCheckbox'

Title: Checkbox Group Input for 'Shiny'
Description: Provides a checkbox group input for usage in a 'Shiny' application. The checkbox group has a head checkbox allowing to check or uncheck all the checkboxes in the group. The checkboxes are customizable.
Authors: Stéphane Laurent [aut, cre], Paul Popov [cph] ('react-input-checkbox' library)
Maintainer: Stéphane Laurent <[email protected]>
License: GPL (>= 3)
Version: 1.0.0
Built: 2024-11-22 02:50:06 UTC
Source: https://github.com/stla/reactcheckbox

Help Index


Define a checkbox

Description

Define a checkbox by its label, its value, and optionally a CSS class.

Usage

checkbox(label, value, class = "")

Arguments

label

the label of the checkbox, can be an ordinary character string, a html character string made with the HTML function, or a shiny.tag object

value

the initial value of the checkbox, TRUE (checked), or FALSE (unchecked)

class

the name of a CSS class to attach to the checkbox, that should be defined with checkboxStyle

Value

A named list, to be used in reactCheckboxesInput.


Checkbox style.

Description

Define CSS styles for a checkbox.

Usage

checkboxStyle(
  checked = NULL,
  checked_hover = NULL,
  unchecked = NULL,
  unchecked_hover = NULL,
  indeterminate = NULL,
  indeterminate_hover = NULL
)

Arguments

checked

styles for the checkbox in checked state

checked_hover

styles for the checkbox in checked state on hover

unchecked

styles for the checkbox in unchecked state

unchecked_hover

styles for the checkbox in unchecked state on hover

indeterminate

styles for the checkbox in indeterminate state (for the head checkbox)

indeterminate_hover

styles for the checkbox in indeterminate state on hover

Value

A named list, to be used in reactCheckboxesInput.

Examples

library(htmltools) # provides the convenient function `css`
checkboxStyle(
  checked = css(
    background.color = "rgba(255, 82, 82, 0.87)",
    border.color = "black"
  ),
  checked_hover = css(
    background.color = "darkred",
    border.color = "darkred"
  )
)

Checkbox group input

Description

Create a checkbox group input for usage in Shiny.

Usage

reactCheckboxesInput(
  inputId,
  checkboxes,
  headLabel = "Check all",
  headClass = "",
  styles = NULL,
  theme = "material"
)

Arguments

inputId

the id that will be used to get the values in Shiny

checkboxes

a list of checkboxes defined with the checkbox function

headLabel

the label for the head checkbox

headClass

a CSS class for the head checkbox

styles

a named list of styles created with the checkboxStyle function; the names denote the CSS classes

theme

the theme, "bootstrap", "fancy", or "material"

Value

A shiny.tag.list object to be included in a Shiny UI.

Examples

library(shiny)
library(htmltools)
library(reactCheckbox)

ui <- fluidPage(
  reactCheckboxesInput(
    "iris",
    list(
      checkbox("Sepal length", FALSE),
      checkbox("Sepal width", FALSE),
      checkbox("Petal length", FALSE),
      checkbox("Petal width", FALSE)
    ),
    headLabel = tags$span(
      "Make a choice", style = "font-size: 1.8rem; font-style: italic;"
    ),
    headClass = "custom",
    theme = "material",
    styles = list(
      "custom" = checkboxStyle(
        checked = css(
          background.color = "darkred"
        ),
        checked_hover = css(
          background.color = "maroon"
        ),
        unchecked = css(
          background.color = "darkorange"
        ),
        unchecked_hover = css(
          background.color = "orange"
        ),
        indeterminate = css(
          background.color = "gold"
        ),
        indeterminate_hover = css(
          background.color = "yellow"
        )
      )
    )
  )
)

server <- function(input, output, session) {
  observe({
    print(input[["iris"]])
  })
}

if(interactive()) {
  shinyApp(ui, server)
}

Update a react checkboxes widget

Description

Change the values of a react checkboxes input.

Usage

updateReactCheckboxInput(session, inputId, values)

Arguments

session

the Shiny session object

inputId

the id of the react checkboxes widget to be updated

values

new values (vector of TRUE or FALSE values)

Value

No returned value, called for side effect.