sendCommand: Send a command to the server

Description Usage Arguments Details Examples

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 sesion.

Usage

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

Examples

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()

anders-biostat/JsRCom documentation built on May 5, 2019, 12:29 a.m.