useShinyjs: Set up a Shiny app to use shinyjs

View source: R/useShinyjs.R

useShinyjsR Documentation

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, as long as the final app UI contains the result of useShinyjs().

Usage

useShinyjs(...)

Arguments

...

Used to catch deprecated arguments.

Details

If you're a package author and including shinyjs in a function in your your package, you need to make sure useShinyjs() is called either by the end user's Shiny app or by your function's UI.

To enable debug mode for shinyjs, set options("shinyjs.debug" = TRUE).

Value

Scripts that shinyjs requires that are automatically inserted to the app's <head> tag.

See Also

runExample extendShinyjs

Examples

if (interactive()) {
  library(shiny)

  shinyApp(
    ui = fluidPage(
      useShinyjs(),  # Set up shinyjs
      actionButton("btn", "Click me"),
      textInput("element", "Watch what happens to me")
    ),
    server = function(input, output) {
      observeEvent(input$btn, {
        # Run a simply shinyjs function
        toggle("element")
      })
    }
  )
}

daattali/shinyjs documentation built on Nov. 16, 2023, 3:08 p.m.