Learn R Programming

shinyjs (version 0.0.6.0)

runjs: Run JavaScript code

Description

Run arbitrary JavaScript code. This is mainly useful when developing and debugging a Shiny app, as it is generally considered dangerous to expose a way for end users to evaluate arbitrary code.

Usage

runjs(...)

Arguments

...
The following parameters are available: ll{ code JavaScript code to run. }

See Also

useShinyjs

Examples

Run this code
if (interactive()) {
  shiny::shinyApp(
    ui = shiny::fluidPage(
      useShinyjs(),  # Set up shinyjs
      shiny::actionButton("btn", "Click me")
    ),
    server = function(input, output, session) {
      shiny::observeEvent(input$btn, {
        # Run JS code that simply shows a message
        runjs("var today = new Date(); alert(today);")
      })
    }
  )
}

Run the code above in your browser using DataLab