add_class: Change the state of a shiny interface element

Description Usage Arguments Note Author(s) See Also Examples

View source: R/css_class.R

Description

Those functions can be used to change an elements classes.

Usage

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

Note

If you have trouble with these functions, please make sure that you either - use any dqshiny element in your UI - load the package with library - use init at the beginning of your UI!

Author(s)

richard.kunze

See Also

Other js handler: enable, hide

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
## 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)
    )
  }
)

}

dqshiny documentation built on May 2, 2019, 1:43 p.m.