if (interactive()) {
  shiny::shinyApp(
    ui = shiny::fluidPage(
      useShinyjs(),  # Set up shinyjs
      shiny::actionButton("btn", "Click me"),
      shiny::p(id = "element", "Watch what happens to me")
    ),
    server = function(input, output, session) {
      shiny::observeEvent(input$btn, {
        # Change the following line for more examples
        toggle("element")
      })
    }
  )
}
# The shinyjs function call in the above app can be replaced by
  # any of the following examples to produce similar Shiny apps
  toggle(id = "element")
  toggle("element", TRUE)
  toggle("element", TRUE, "fade", 2)
  toggle(id = "element", time = 1, anim = TRUE, animType = "slide")
  show("element")
  show(id = "element", anim = TRUE)
  hide("element")
  hide(id = "element", anim = TRUE)
## toggle can be given an optional `condition` argument, which
## determines if to show or hide the element
if (interactive()) {
  shiny::shinyApp(
    ui = shiny::fluidPage(
      useShinyjs(),
      shiny::checkboxInput("checkbox", "Show the text", TRUE),
      shiny::p(id = "element", "Watch what happens to me")
    ),
    server = function(input, output, session) {
      shiny::observe({
        toggle(id = "element", condition = input$checkbox)
      })
    }
  )
}Run the code above in your browser using DataLab