Graphics display issues with R built from source for RStudio Server

Hi All,

I am having some trouble getting plots to display in our RStudio Server interactive app. We are running this app without Singularity, in the same manner as described in this post. The R interpreter we use for this, we built from source, but I suspect I’m missing some libraries, or compiler flags, or both. When we try to run a plot in RStudio Server, we get this error:

Error in RStudioGD() : 
  Shadow graphics device error: r error 4 (R code execution error)
In addition: Warning message:
In grDevices:::png("/tmp/RtmpHm70aN/206c218b33c34010a3a833ac7bc55509.png",  :
  unable to open connection to X11 display ''

This makes sense, because in a browser window, we wouldn’t have an X11 display device. Some searching around on the internet suggests that we may be missing libcairo, libjpeg, and possibly some others. I have tried building these, and other libraries, into our source build, but I am still unable to resolve this issue.

Does anyone have a recipe for building R from source so that it runs correctly within RStudio Server?

Thanks,
Nick

Actually, I think it could be simpler than that. It seems to be taking issue with /tmp/RtmpHm70aN directory, that you don’t have write access to it?

This is a similar Github issue on the RStudio repo.

Actually, I do have write access to that directory, and to the .png image it’s complaining about. The issue – at least in my reading of the error message – seems to be RStudio’s inability to open the X11 connection.

Here they recommend running capabilities() to check if support is available for various libraries. This is what I get:

> capabilities()
       jpeg         png        tiff       tcltk         X11        aqua    http/ftp     sockets 
      FALSE       FALSE       FALSE       FALSE       FALSE       FALSE        TRUE        TRUE 
     libxml        fifo      cledit       iconv         NLS     profmem       cairo         ICU 
       TRUE        TRUE        TRUE        TRUE        TRUE       FALSE       FALSE       FALSE 
long.double     libcurl 
       TRUE        TRUE 

The output indicates I’m missing support for all the major image types and X11 (among other things).

Nick

I see. OK. here are my capabilities. I think what you need is the png capability. Not sure about X11 but some stack overflow topics seem to indicate you need cario (you see I don’t have X11 but I do have cario).

> capabilities()
       jpeg         png        tiff       tcltk         X11        aqua    http/ftp     sockets      libxml        fifo 
       TRUE        TRUE        TRUE        TRUE       FALSE       FALSE        TRUE        TRUE        TRUE        TRUE 
     cledit       iconv         NLS     profmem       cairo         ICU long.double     libcurl 
       TRUE        TRUE        TRUE       FALSE        TRUE        TRUE        TRUE        TRUE 

Can you run the png() function? I keep getting NULL even though I can link to an image, but I never get an error thrown.

> png()
> png('/tmp/foo')
> foo = png('/tmp/foo')
> png('/users/PZS0714/johrstrom/ondemand/dev/codeserver/icon.png')
> icon = png('/users/PZS0714/johrstrom/ondemand/dev/codeserver/icon.png')

Here’s what I get when I run png():

Error in .External2(C_X11, paste0("png::", filename), g$width, g$height,  : 
  unable to start device PNG
In addition: Warning message:
In png() : unable to open connection to X11 display ''

Re: Cairo, that’s the conclusion I came to as well. That’s why I was wondering if anyone had a recipe for an R source build I could try that has a working graphics component with RStudio Server.

How did you build your R installation?

We had the same issue a while back. It has to do with plotting in R on a headless server. If memory serves, the solution was to add options(bitmapType='cairo') to /{RInstallDir}/lib64/R/etc/Rprofile.site. You might need to create that file if you don’t already have it.

You also need the graphics capabilities. For building R at our site, we use:
./configure --prefix=/apps/R/4.0.0 --enable-R-shlib --with-x --with-cairo --with-jpeglib --with-readline --with-tcltk --with-blas --with-lapack --enable-R-profiling --enable-memory-profiling

It’s been a while since we fixed this so your mileage may vary.