shinyjs (version 2.1.0)

runjs: Run JavaScript code

Description

Run arbitrary JavaScript code.

Usage

runjs(code)

Arguments

code

JavaScript code to run.

See Also

useShinyjs

Examples

Run this code
# NOT RUN {
if (interactive()) {
  library(shiny)
  shinyApp(
    ui = fluidPage(
      useShinyjs(),  # Set up shinyjs
      actionButton("btn", "Click me")
    ),
    server = function(input, output) {
      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 DataCamp Workspace