An R package to exchange commands between R and JavaScript. It opens a new or an existing web page and establishes a WebSocket connection to the currently running R session.
install.packages("jrc")Main R functions are sendData(), sendCommand(), callFunction(), and sendHTML(). The first one sends a variable
from the R session to the web page, the second one executes a JavaScript code, the third one calls a JavaScript function (optionally, with the specified arguments), and the last one
adds some HTML to the web page.
Their JavaScript counterparts are jrc.sendData(), jrc.callFunction(), and jrc.sendCommand().
openPage() and closePage() respectively opens and closes a web page.
This example opens a new page and adds there a button, that increases value of k by one in the
R session.
library(jrc)
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"))