Learn R Programming

dqshiny (version 0.0.4)

add_class: Change the state of a shiny interface element

Description

Those functions can be used to change an elements classes.

Usage

add_class(ids, class_name)

remove_class(ids, class_name)

toggle_class(ids, class_name, condition = NULL)

Arguments

ids

Character vector, id(s) of the element(s) to change.

class_name

Name of the class to add/remove/toggle.

condition

Condition to use for toggling the class, can be of length one or length of ids.

See Also

Other js handler: enable(), hide()

Examples

Run this code
# NOT RUN {
## Only run examples in interactive R sessions
if (interactive()) {

library(shiny)
shinyApp(
  ui = fluidPage(
    tags$head(tags$style(".orange{background:#ff8f00}")),
    actionButton("add", "Add Class"),
    actionButton("remove", "Remove Class"),
    actionButton("toggle", "Toggle Class"),
    actionButton("toggle_cond", "Toggle Class with Condition"),
    checkboxInput("condition", "orange"),
    fluidRow(id = "row",
      dq_space(), # this is needed to make everything work
      actionButton("example", "EXAMPLE"),
      dq_space() # this is just for the alignment ;)
   )
  ),
  server = function(input, output) {
    observeEvent(input$add, add_class("row", "orange"))
    observeEvent(input$remove, remove_class("row", "orange"))
    observeEvent(input$toggle, toggle_class("row", "orange"))
    observeEvent(
      input$toggle_cond,
      toggle_class("row", "orange", input$condition)
    )
  }
)

}
# }

Run the code above in your browser using DataLab