Skip to content
Gordon Woodhull edited this page Feb 26, 2015 · 4 revisions

Creating RCloud session from a notebook

This wiki discusses the API for a webpage to create an RCloud session and call a notebook.

mini.html

The current proof of concept is mini.html which works as follows:

  • load minimal RCloud JS dependencies
  • define onLoad function that does the following:
    • creates an RCloud connection
    • parses notebook and version query string parameters
    • calls the notebook with the ID specified in notebook and version version
    • assigns the result in window.notebook_result (so it is accessible by arbitrary callback code later - better ideas are welcome)
    • if the result is a list containing a named element body, append its content in the <body> DOM element
    • if the result is a list containing a named element run which is a function, call it with named list containing the parsed query

There is currently no error handling - any errors will get logged to the browser console.

The rationale is that the notebook can pass arbitrary functions that are converted to JS promises automatically and can be called from any subsequent JS code. The special case of run allows an onload-like callback into R to proceed in a fully initialized session. The body element allows a notebook to generate content, very much like notebook.R.

The difference between mini.html and notebook.R is that the latter merely delivers HTML, while the former can also register callbacks and has a running RCloud session available as long as the page is open.