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


Many popular plotting packages require cairo, a graphics device that relies on an X11 server. However, nothing that depends on X11 will work on RStudio Server Pro 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 RStudio Server Pro.

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 Server Pro 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 RStudio Server Pro.

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 remove RStudio Server Pro 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 RStudio 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)