
Last chance! 50% off unlimited learning
Sale ends in
Sends a variable to a web page, where it is saved under a specified name. This function
is a wrapper around sendData
method of class Session
.
sendData(
variableName,
variable,
keepAsVector = FALSE,
rowwise = TRUE,
sessionId = NULL,
wait = 0
)
Name that the variable will have on the web page.
Variable to send.
If TRUE
, variables with length 1 will be saved as arrays on the web page, otherwise they
will be converted to atomic types.
If TRUE
, matrices and data.frames will be transformed into JavaScript objects or arrays
row wise (e.g. a matrix will become an Array of its rows).
An ID of the session to which the data should be sent. Can also be a vector of multiple session IDs.
If NULL
, the data will be sent to all currently active sessions.
If wait > 0
, after sending the message, R will wait for a reply for a given number of seconds.
For this time (or until the reply is received), execution of other commands will be halted. Any incoming message
from the session will be considered as a reply.
To send data back from the web page to the current R session one should usejrc.sendData(variableName, variable, internal)
.
Its arguments are:
variableName
Name that the variable will have in the R session. If variable name hasn't been previously added to the list
of allowed variables (see allowVariables
or allowedVariables
argument of the openPage
function), attempt to assign it from a web page will require manual authorization on the R side.
variable
Variable to send.
internal
(optional)Whether this variable should be used only by the session that sent it. If true
, variable will be stored
in the session-specific environment and can be accessed from the outside with getSessionVariable
function. If false
, variable will be saved to the outer environment of the app (see setEnvironment
).
By default, uses true
for variables that already exist in the session specific environment
(see setSessionVariables
or sessionVariables
argument of the openPage
function.)
and false
otherwise.
authorize
, allowVariables
, sendCommand
,
callFunction
, sendHTML
, openPage
, getSessionIds
.
# NOT RUN {
openPage()
x <- 1:100
sendData("x", x)
sendCommand("console.log(x);")
sendCommand("jrc.sendData('x', x.filter(function(e) {return e % 2 == 0}))")
closePage()
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab