Configuration

This section describes how to configure the example page, shown below. The upper-region has controls for experimenting with the Tutorial API calls, and the lower region is an <iframe> hosting RStudio Workbench.

Example Page

Allow IFrame

For security reasons, RStudio will not load inside a browser frame (such as an iframe) by default. You can modify this behavior by using the www-frame-origin option. See Frame Origin for full details.

To enable the Tutorial API example page to host RStudio Workbench on a non-production localhost server, do the following:

# /etc/rstudio/rserver.conf
www-frame-origin=http://localhost:8080
Note

If the www-frame-origin option is set to same or any instead of a URI, you must add the following setting with the actual URI:

# /etc/rstudio/rsession.conf
tutorial-api-client-origin=http://localhost:8080

Enable API Calls from Host Page

To enable calling the Tutorial APIs from the hosting page:

# /etc/rstudio/rsession.conf
tutorial-api-enabled=1

Enable Callbacks from RStudio to Host Page

RStudio may optionally notify the hosting page of certain events using the JavaScript PostMessage mechanism.

The receiver is responsible for parsing, interpreting, and reacting to the value of the callbacks. Any JavaScript running in the context of the IDE iframe could do an arbitrary SendMessage to the parent (in addition to those being generated by the RStudio IDE JavaScript). The host page should ensure the response string is valid JSON, and follows one of the patterns described in Tutorial API Callbacks.

To enable callbacks:

# /etc/rstudio/rsession.conf
tutorial-api-parent-notify-enabled=1

Disable RStudio Workbench Home Page

The Tutorial API cannot be used to manipulate the RStudio Workbench Home Page. To disable the home page:

# /etc/rstudio/rserver.conf
server-user-home-page=0
Note

The server-user-home-page setting is automatically forced on if Job Launcher sessions are enabled via launcher-sessions-enabled=true in /etc/rstudio/rserver.conf.

Disable Multiple Session Support

Even with the Home Page disabled, a user can still open new sessions via Session / New Session which will open a new IDE instance outside of the host page. To prevent this:

# /etc/rstudio/rserver.conf
server-multiple-sessions=0

If multiple sessions are disabled, the Home Page is automatically turned off, so not necessary to include both settings.

Note

The server-multiple-sessions setting is automatically forced on when Job Launcher sessions are enabled via launcher-sessions-enabled=true in /etc/rstudio/rserver.conf.

Serve the Example Page

Serve the folder /usr/lib/rstudio-server/extras/tutorial with a web server. For example, change to that directory in a terminal and run this command:

python -m SimpleHTTPServer 8080

Load http://localhost:8080/demo.htm in a web browser and you should see the page shown earlier.