useShinyjs: Set up a Shiny app to use shinyjs

Description Usage Arguments Details Value See Also Examples

View source: R/useShinyjs.R

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

1

Arguments

rmd

Set this to TRUE only if you are using shinyjs inside an interactive R markdown document. If using this option, view the README online to learn how to use shinyjs in R markdown documents.

debug

Set this to TRUE if you want to see detailed debugging statements in the JavaScript console. Can be useful when filing bug reports to get more information about what is going on.

html

Set this to TRUE only if you are using shinyjs in a Shiny app that builds the entire user interface with a custom HTML file. If using this option, view the README online to learn how to use shinyjs in these apps.

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.

Value

Scripts that shinyjs requires that are automatically inserted to the app's <head> tag. A side effect of calling this function is that a shinyjs directory is added as a resource path using shiny::addResourcePath().

See Also

runExample extendShinyjs

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
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")
      })
    }
  )
}

Example output

Attaching package: 'shinyjs'

The following objects are masked from 'package:methods':

    removeClass, show

shinyjs documentation built on Dec. 23, 2021, 5:06 p.m.