| sendCommand | R Documentation |
sendCommand sends JavaScript code through the selected WebSocket connection and evaluates it on the specified
web page. Use JavaScript function jrc.sendCommand to send R code from the web page
and evaluate it in the current R session. All commands send to R from the server will be evaluated
only after authorization in the currently running R session (see authorize).
sendCommand(command, sessionId = NULL, wait = 0)
command |
A line (or several lines separated by |
sessionId |
An ID of the session to which the command should be sent. Can also be a vector of multiple session IDs.
If |
wait |
If |
Each opened page gets its own environment, where all the commands are evaluated. Any changes
made with the usual assignment operator <- will be limited to this page-specific environment. The changes
are still saved, but can be accessed only with getSessionVariable function. To make changes outside
of the page-specific environment use <<- instead.
In JavaScript one should use windows.varibleName = "SomeValue"
instead of varibleName = "SomeValue", in order to make the variable accessible outside of the
current sendCommand call.
This function is a wrapper around sendCommand method of class Session.
authorize, sendData, sendHTML, callFunction,
openPage, getSessionIds.
## Not run:
# to run this example an installed web browser is required
k <- 0
openPage()
sendCommand(paste0("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()
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.