Learn R Programming

jrc (version 0.2.1)

sendCommand: Send a command to the server

Description

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 session. All commands send to R from the server will be executed only after authorization in the currently running R session.

Usage

sendCommand(command)

Arguments

command

A line (or several lines separated by \n) of JavaScript code. This code will be immediately executed on the opened page. No R-side syntax check is performed.

Details

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 accessible only within the current sendCommand call.

See Also

authorize, sendData, sendHTML, callFunction, openPage.

Examples

Run this code
# NOT RUN {
 
# }
# NOT RUN {
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()
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab