runjs: Run JavaScript code

Description Usage Arguments Note See Also Examples

View source: R/jsFunc-runjs.R

Description

Run arbitrary JavaScript code.

Usage

1
runjs(code)

Arguments

code

JavaScript code to run.

Note

shinyjs must be initialized with a call to useShinyjs() in the app's ui.

See Also

useShinyjs

Examples

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

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.