html_class: Add or remove a class from an HTML element

Description Usage Arguments See Also Examples

View source: R/class.R

Description

html_class will add or remove a class from an HTML element. html_addclass and html_unclass are shortcut functions.

Usage

1
2
3
4
5
html_class(id, classname, add = TRUE)

html_unclass(id, classname)

html_addclass(id, classname)

Arguments

id

shiny input id

classname

class name

add

if TRUE, class will be added, if FALSE class will be deleted

See Also

Other javascript functions: ability, activate, click_event, html_toogle

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
library(shinytools)
classes <- c("primary", "secondary", "success",
             "danger", "warning", "info")

if (interactive()) {
  options(device.ask.default = FALSE)

  ui <- fluidPage(
    titlePanel("Hello dghiesse!"),
    load_jstools(),
    sidebarLayout(
      sidebarPanel(
        selectInput("class", "Variable:", classes)
      ),
      mainPanel(
        actionButton("anybutton", "watch this button",
                     class = "btn-info")
      )
    )
  )

  server <- function(input, output) {
    observeEvent(input$class, {
      for(i in classes){
        html_unclass("anybutton", paste0("btn-", i))
      }
      html_addclass("anybutton", paste0("btn-", input$class))
    })
  }

  print(shinyApp(ui, server))
}

ardata-fr/shinytools documentation built on Nov. 15, 2019, 7:53 p.m.