Working with packages that require X11 and/or cairo on Posit Workbench / RStudio Server

Follow
Note: This article explains how to use interactive X11 windowing functionality on a remote server. You might also be working on a remote machine with Posit Workbench (previously RStudio Server Pro) that has the X11 system packages installed (e.g., if you installed precompiled R binaries that depend on X11) to support the generation of plots and graphics using different backends. In that case, you can continue to use R and X11 on a remote or headless machine with RStudio Workbench to generate plots and graphics on the server-side without having to SSH into the remote server with X11 forwarding enabled.

Many popular plotting packages require cairo, a graphics device that relies on an X11 server. However, nothing that depends on X11 will work on Posit Workbench natively, including tcl/tk or cairo. These packages require access to a display, which is not available on Linux systems.

This is not unusual; most graphical programs cannot be run directly on Linux servers, and R packages that require cairo are no exception. For that reason, we recommend you do not try to run R code that relies on X11 from within Posit Workbench.

However, there is a way to run graphics remotely if you:

  1. Install an X11 server locally,
  2. Establish an SSH tunnel (ssh -TX -R <RSP Host port>:localhost:<local port> [<user>@]<RSP Host>) from your local machine to the RStudio Workbench host, and
  3. Set the DISPLAY environment variable (most likely to localhost:10.0).

To ensure that each R Session has the correct value for the DISPLAY environment variable, you may wish to set it in the rsession-profile file (/etc/rstudio/rsession-profile).

Please note that an X11 server and SSH tunnel will be required for each user that wishes to use X11 forwarding. Additionally, the SSH tunnel must be established by the same user account that will login to Posit Workbench.

After the the X11 server and SSH tunnel are running, you will need to restart R. With this configuration, your local X11 server will display the graphics served by the remote Posit Workbench instance. This is roughly equivalent to your setting up the SSH configuration to support X11 forwarding.

Setting up the local X11 server, configuring SSH, and setting your DISPLAY variable are outside the scope of Posit Support, but this article describes the process, and includes steps for various client operating systems:

How do I run graphical programs remotely from a Linux server?

To set the DISPLAY environment variable, see this page:

X11 - DISPLAY (environment variable)

Comments