DOM-package: Drive web browser content from R.

Description Details Author(s) See Also Examples

Description

Drive web browser content from R.

Details

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:

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

Author(s)

Paul Murrell

See Also

htmlPage

Examples

1
2
3
headlessPage <- htmlPage(client=phantomClient)
appendChild(headlessPage, htmlNode("<p>test</p>"))
closePage(headlessPage)

pmur002/DOM documentation built on May 25, 2019, 10:20 a.m.