Learn R Programming

shinyjs (version 0.0.3.3)

visibilityFuncs: Display/hide an element

Description

Display or hide an HTML element.

Usage

show(...)

hide(...)

toggle(...)

Arguments

...
The following parameters are available: ll{ id The id of the element/Shiny tag anim If TRUE then animate the behaviour

Details

show makes an element visible, hide makes an element invisible, toggle displays the element if it it hidden and hides it if it is visible.

See Also

useShinyjs, runExample, hidden

Examples

Run this code
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::observe({
        if (input$btn == 0) {
          return(NULL)
        }
        # 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)

Run the code above in your browser using DataLab