Description Usage Arguments Details Examples
sendCommand
sends JavaScript code to the server and executes it on the currently
opened page. Use JavaScript function jrc.sendCommand
to send R code from the server
and execute it in the current R sesion.
1 | sendCommand(command)
|
command |
A line (or several lines separated by |
Note, that in both cases commands are executed inside a function. Therefore use for R code use <<-
instead
of <-
to change global variables and in JavaScript use windows.varibleName = "SomeValue"
or
varibleName = "SomeValue"
. Variables declared like var variableName = "SomeValue"
or
variableName <- "SomeValue"
will be accessable only within the current sendCommand
call.
1 2 3 4 5 6 7 8 9 |
k <- 0
openPage()
sendCommand(str_c("button = document.createElement('input');",
"button.type = 'button';",
"button.addEventListener('click', function() {jrc.sendCommand('k <<- k + 1')});",
"button.value = '+1';",
"document.body.appendChild(button);", collapse = "\%n"))
closePage()
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.