Description Details Author(s) See Also
Call an R function from javascript code in a web page.
This is not an R function; it is a javascript function that is available within the web page that R is connected to. It can be used to call an R function from the web page, e.g., in response to a user event, and optionally run a callback function in the web page when the R function returns a result.
The RDOM.Rcall
function takes four arguments:
The name of the R function to call (as a string).
A reference to a DOM node (or a collection of DOM nodes).
An array of types that determine how the nodes will be
represented in R (one or more of "HTML"
, "SVG"
,
"CSS"
, "XPath"
).
A callback function (or null
).
A typical usage might look like this (to call an R function when a button is clicked on the web page):
1 | <button onclick='RDOM.Rcall("fnname", this, [ "HTML" ], null)'>
|
The R function that is called by RDOM.Rcall
is provided with
a variable number of arguments equal to the number of DOM nodes times
the number of node types (with the number of types changing fastest).
In the example above, the R function would receive only one argument.
It is also possible to pass raw javascript values in the second
argument, instead of DOM nodes. In this case, the type argument
should be one of "string"
, "number"
, "boolean"
,
or "JSON"
(for more complex sets of values).
The return value of the R function (if any) is converted to a JSON
object and passed to the callback function specified
in the call to RDOM.Rcall
).
Paul Murrell
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.