Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using rgl with headless display

Tags:

shell

r

xvfb

rgl

I installed Xfvb and instantiated a display instance:

$ Xvfb :2 -screen 0 1280x960x24 &

I then installed R 3.2.5 and rgl 0.95.1441 separately from source, and I opened R with a connection to DISPLAY on port 2. I then tried to run a test rgl session with some basic rgl routines:

$ DISPLAY=:2 /usr/local/bin/R
R version 3.2.5 (2016-04-14) -- "Very, Very Secure Dishes"
...
> library(rgl)
> open3d()
> x <- sort(rnorm(1000))
> y <- rnorm(1000)
> z <- rnorm(1000) + atan2(x,y)
glX
 1
> plot3d(x, y, z, col=rainbow(1000))
> rgl.postscript("foo.pdf", fmt="pdf")
> sessionInfo()

The rgl.postscript() command here should print out a PDF file containing the rendering of the data points passed to plot3d(). However, the resulting PDF file is blank.

Is there a configuration issue with how I installed or instantiated Xvfb and/or R, which is causing display problems?


Here is a log of a typical run session:

R version 3.2.5 (2016-04-14)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Fedora release 14 (Laughlin)

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C
 [9] LC_ADDRESS=C               LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  base

other attached packages:
[1] rgl_0.95.1441  optparse_1.3.2

loaded via a namespace (and not attached):
[1] getopt_1.20.0 methods_3.2.5

5 XSELINUXs still allocated at reset
SCREEN: 0 objects of 136 bytes = 0 total bytes 0 private allocs
DEVICE: 4 objects of 32 bytes = 128 total bytes 0 private allocs
CLIENT: 0 objects of 160 bytes = 0 total bytes 0 private allocs
WINDOW: 0 objects of 48 bytes = 0 total bytes 0 private allocs
PIXMAP: 1 objects of 16 bytes = 16 total bytes 0 private allocs
GC: 0 objects of 56 bytes = 0 total bytes 0 private allocs
CURSOR: 0 objects of 8 bytes = 0 total bytes 0 private allocs
CURSOR_BITS: 0 objects of 8 bytes = 0 total bytes 0 private allocs
DBE_WINDOW: 0 objects of 24 bytes = 0 total bytes 0 private allocs
TOTAL: 5 objects, 144 bytes, 0 allocs
4 DEVICEs still allocated at reset
DEVICE: 4 objects of 32 bytes = 128 total bytes 0 private allocs
CLIENT: 0 objects of 160 bytes = 0 total bytes 0 private allocs
WINDOW: 0 objects of 48 bytes = 0 total bytes 0 private allocs
PIXMAP: 1 objects of 16 bytes = 16 total bytes 0 private allocs
GC: 0 objects of 56 bytes = 0 total bytes 0 private allocs
CURSOR: 0 objects of 8 bytes = 0 total bytes 0 private allocs
CURSOR_BITS: 0 objects of 8 bytes = 0 total bytes 0 private allocs
DBE_WINDOW: 0 objects of 24 bytes = 0 total bytes 0 private allocs
TOTAL: 5 objects, 144 bytes, 0 allocs
1 PIXMAPs still allocated at reset
PIXMAP: 1 objects of 16 bytes = 16 total bytes 0 private allocs
GC: 0 objects of 56 bytes = 0 total bytes 0 private allocs
CURSOR: 0 objects of 8 bytes = 0 total bytes 0 private allocs
CURSOR_BITS: 0 objects of 8 bytes = 0 total bytes 0 private allocs
DBE_WINDOW: 0 objects of 24 bytes = 0 total bytes 0 private allocs
TOTAL: 1 objects, 16 bytes, 0 allocs

In addition to Fedora 14, I have also tested the same version of R and rgl under CentOS Linux release 7.2.1511.

On the Fedora 14 box, I am running:

xorg-x11-server-Xvfb.x86_64   v1.9.5-2.fc14

On the CentOS 7 box, I am running:

xorg-x11-server-Xvfb.x86_64   v1.17.2-10.el7

Under both test servers, when I run my test R script, I get a white, empty PDF from rgl.postscript() and black, empty PNG from rgl.snapshot() (along with the same Xvfb log statements).

I should stress that I am looking to create a PDF file containing the rendered scene, which is in a vector-based format. While rgl.snapshot() may help with troubleshooting the cause of the problem, that call returns a PNG bitmap, not a vector-formatted PDF. A bitmap is not useful as a final product for my purposes.

In addition to running R with the DISPLAY variable setting passed to it, I also have used export:

$ DISPLAY=:2 /usr/local/bin/R

Or:

$ export DISPLAY=":2" 
$ /usr/local/bin/R
...

Either approach yields the same results.

If other details would be of use, please feel free to leave a comment with specifics and I'll do what I can to follow up.


Neither the Fedora 14 nor the CentOS 7 box should have proprietary libgl drivers. To the best of my knowledge, these are standalone, headless servers. The Fedora 14 box is actually a virtual machine. If there is a specific way to confirm, please let me know.

I have the following Xdummy package installed under the Fedora 14 headless server:

xorg-x11-drv-dummy.x86_64   v0.3.4-1.fc14

On the CentOS 7 machine:

xorg-x11-drv-dummy.x86_64   v0.3.6-21.el7

On the CentOS 7 server, I run the Xdummy script to create a display on :10:

$ sudo ./Xdummy -debug :10 -depth 16 -geom 1024x768

In another shell, I run R and the test rgl routines:

$ DISPLAY=":10" /usr/local/bin/R
...
> library(rgl)
> open3d()
> x <- sort(rnorm(1000))
> y <- rnorm(1000)
> z <- rnorm(1000) + atan2(x,y)
> plot3d(x, y, z, col=rainbow(1000))
> rgl.postscript("foo.pdf", fmt="pdf")

As with Xvfb, the resulting PDF file is a blank document and contains no data points.

like image 563
Alex Reynolds Avatar asked May 30 '16 08:05

Alex Reynolds


1 Answers

This seems to be intimately intertwined with the rgl package. Suppose we toss Xvfb and friends in favor of Cairo and substitute plot3D for rgl:

library(Cairo)
library(plot3D)
CairoPDF()
x <- sort(rnorm(1000))
y <- rnorm(1000)
z <- rnorm(1000) + atan2(x, y)
scatter3D(x, y, z)
dev.off()

This still needs to run under X11 (i.e. xterm) but avoids bringing up an X11 window and leaves a PDF plot behind in Rplots.pdf (you can control the file names, of course along with lots of the other details of the plot.)

enter image description here

(Converted to JPEG for insertion here, but it is truly a PDF.)

like image 87
cdlane Avatar answered Oct 27 '22 11:10

cdlane