JS: Mark character strings as literal JavaScript code

Description Usage Arguments Author(s) Examples

View source: R/utils.R

Description

This function JS() marks character vectors with a special class, so that it will be treated as literal JavaScript code when evaluated on the client-side.

Usage

1

Arguments

...

character vectors as the JavaScript source code (all arguments will be pasted into one character string)

Author(s)

Yihui Xie

Examples

1
2
3
4
library(htmlwidgets)
JS('1 + 1')
list(x = JS('function(foo) {return foo;}'), y = 1:10)
JS('function(x) {', 'return x + 1;', '}')

Example output

[1] "1 + 1"
attr(,"class")
[1] "JS_EVAL"
$x
[1] "function(foo) {return foo;}"
attr(,"class")
[1] "JS_EVAL"

$y
 [1]  1  2  3  4  5  6  7  8  9 10

[1] "function(x) {\nreturn x + 1;\n}"
attr(,"class")
[1] "JS_EVAL"

htmlwidgets documentation built on July 10, 2017, 5:03 p.m.