Description Details Author(s) See Also Examples
Drive web browser content from R.
Start a web browser from R and manipulate the document content in the browser from R (using a websocket connection).
There are three options for the initial web page:
htmlPage opens a page with the web page <body>
given in the call (default is a blank page).
filePage opens a web page from a file on the
local filesystem.
urlPage opens a web page with the given URL
(though only http: is currently supported.
Once the connection to the web page is established, functions are
provided to perform basic DOM operations on the document content,
e.g., appendChild, removeChild,
setAttribute, and so on.
The DOM operations can be synchronous, in which case R blocks until a response is received from the browser, or asynchronous (with a callback).
It is also possible to use RDOM.Rcall within javascript
on the web page to (asynchronously) make a request to R from the
browser (e.g., in response to a user event such as a mouse click).
The connection to the browser should be closed with
closePage.
The hidden function DOM:::debug(page) can be used to turn on
debugging output in both R and the browser.
The timeout for requests sent to the browser is controlled by
options("DOM.limit") (default 5 [seconds]). Setting this
larger can be useful to stop R timing out while debugging in the
browser.
The hidden function DOM:::getPage(page) can be used to obtain
the current page content.
The hidden function DOM:::render(page, outfile can be used to
produce a PNG file rendering of the current page in a headless
browser. The width and height of the image are controlled via
options("DOM.width") and options("DOM.height").
The width and height must be set BEFORE opening a web page
(i.e., before the call to htmlPage()).
The environment variable R_PHANTOMJSCMD can be used to
specify the path to the phantomJS executable (for the headless
browser).
Paul Murrell
1 2 3 | headlessPage <- htmlPage(client=phantomClient)
appendChild(headlessPage, htmlNode("<p>test</p>"))
closePage(headlessPage)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.