我经常在没有 X11 的 linux 集群计算节点上运行 jupyter IPython notebooks,没有任何问题。然而,在相同的设置上运行 R 内核并不是很好。
机器的详细信息是:
- CentOS 7.2
- 具有 X11、png 和 cairo 功能的 R 3.3.1
- python 4.0.0( python 2.7.11)
在日志中使用此运行第一个单元格后,仅启动笔记本会导致内核崩溃:
unable to open connection to X11 display ''
我可以通过使用 xvfb-run jupyter notebook
启动笔记本来让它工作。这让我可以在单元格中运行 R 命令,但是当我尝试生成绘图时,我得到以下信息
Error in grid.Call(L_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : X11 font -adobe-helvetica-%s-%s-*-*-%d-*-*-*-*-*-*-*, face 1 at size 9 could not be loaded
我想如果我可以安装 x11 字体它会工作,但这是在集群的计算节点上,我没有安装它们的管理权限。
使用 R 内核配置 jupyter notebook 以在没有 X11 的 linux 机器上生成图形的正确方法是什么?
最佳答案
我认为我已经找到了在没有显示硬件和物理输入设备的 Linux 机器上运行笔记本时 irkernel 所需的最小配置。
在虚拟帧缓冲区 X 服务器下运行笔记本,xvfb:
xvfb-run jupyter notebook
使用 cairo 代替 X11:
# Run this in a notebook cell, or put in .Rprofile
options(bitmapType="cairo")
设置 jupyter.plot_mimetype。 SVG 看起来好多了,对我来说效果很好。 PNG 也可以:
# Run this in a notebook cell, or put in .Rprofile
# svg much clearer, but won't rescale (scrolling works though)
options(jupyter.plot_mimetypes = "image/svg+xml")
# png had some artifacts, but had the nice feature that it would
# resize when the browser window changes size
#options(jupyter.plot_mimetypes = 'image/png')
# can easily resize plots (have to re-plot) with this:
#options(repr.plot.width=14, repr.plot.height=4)
关于r - 如何在没有显示器的机器上运行带有内联图形的 jupyter Rkernel notebook?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37999772/