我安装了Xfvb并实例化了一个显示实例:
$ Xvfb :2 -screen 0 1280x960x24 &
然后,我从源代码分别安装了R 3.2.5和rgl 0.95.1441,并通过与端口2上的
DISPLAY
的连接打开了R,然后我尝试使用一些基本的rgl例程运行测试rgl session :$ 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()
此处的
rgl.postscript()
命令应打印出一个PDF文件,其中包含传递给plot3d()
的数据点的呈现。但是,生成的PDF文件为空白。我如何安装或实例化Xvfb和/或R是否存在配置问题,这会导致显示问题?
这是典型运行 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
除了Fedora 14外,我还在CentOS Linux版本7.2.1511下测试了相同版本的
R
和rgl
。在Fedora 14框上,我正在运行:
xorg-x11-server-Xvfb.x86_64 v1.9.5-2.fc14
在CentOS 7框上,我正在运行:
xorg-x11-server-Xvfb.x86_64 v1.17.2-10.el7
在两个测试服务器上,当我运行测试
R
脚本时,我从rgl.postscript()
中得到一个白色的空白PDF,从rgl.snapshot()
中得到一个黑色的空白PNG(以及相同的Xvfb
日志语句)。我要强调的是,我要创建一个包含渲染场景的PDF文件,该文件为基于矢量的格式。尽管
rgl.snapshot()
可能有助于解决问题的原因,但该调用返回的是PNG位图,而不是矢量格式的PDF。对于我而言,位图作为最终产品没有用。除了使用传递给
R
变量的设置来运行DISPLAY
之外,我还使用了export
:$ DISPLAY=:2 /usr/local/bin/R
或者:
$ export DISPLAY=":2"
$ /usr/local/bin/R
...
两种方法都会产生相同的结果。
如果其他细节有用,请随时发表评论,我会尽力跟进。
Fedora 14和CentOS 7包装盒都不应具有专有的libgl驱动程序。据我所知,这些是独立的 headless 服务器。 Fedora 14盒子实际上是一个虚拟机。如果有特定的确认方法,请告诉我。
我在Fedora 14 headless 服务器下安装了以下
Xdummy
软件包:xorg-x11-drv-dummy.x86_64 v0.3.4-1.fc14
在CentOS 7机器上:
xorg-x11-drv-dummy.x86_64 v0.3.6-21.el7
在CentOS 7服务器上,我运行Xdummy脚本在
:10
上创建显示:$ sudo ./Xdummy -debug :10 -depth 16 -geom 1024x768
在另一个shell中,我运行R和test rgl例程:
$ 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")
与
Xvfb
一样,生成的PDF文件为空白文档,不包含任何数据点。 最佳答案
这似乎与rgl
包紧密地交织在一起。假设我们抛弃Xvfb
和 friend ,转而使用Cairo
,并用plot3D
代替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()
这仍然需要在X11(即xterm)下运行,但避免出现X11窗口,而在
Rplots.pdf
中留下PDF图(您可以控制文件名,当然还有图的许多其他细节。)(已转换为JPEG以在此处插入,但实际上是PDF。)
关于r - 搭配 headless 显示器使用RGL,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37521259/