sendCommand {jrc} | R Documentation |
Send a command to a web page
Description
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
).
Usage
sendCommand(command, sessionId = NULL, wait = 0)
Arguments
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 |
Details
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
.
See Also
authorize
, sendData
, sendHTML
, callFunction
,
openPage
, getSessionIds
.
Examples
## 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)