Learn R Programming

shinyjs (version 0.1.0)

useShinyjs: Set up a Shiny app to use shinyjs

Description

This function must be called from a Shiny app's UI in order for all other shinyjs functions to work. You can call useShinyjs() from anywhere inside the UI.

Usage

useShinyjs(rmd = FALSE)

Arguments

rmd
Set this to TRUE if you are using shinyjs inside an interactive R markdown document. For regular Shiny apps use the default value of FALSE.

Value

  • Scripts that shinyjs requires that are automatically inserted to the app's tag.

See Also

runExample extendShinyjs

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) {
      shiny::observe({
        if (input$btn == 0) {
          return(NULL)
        }
        # Run a simply shinyjs function
        toggle("element")
      })
    }
  )
}

Run the code above in your browser using DataLab