如何运行 jupyter Rkernel notebook with inline graphics on machine without display?

How to run jupyter Rkernel notebook with inline graphics on machine without display?

我经常 运行 jupyter IPython notebooks 在没有 X11 的 linux 集群计算节点上没有问题。然而,运行在相同的设置上使用 R 内核并不是很好。

机器详细信息是:

在日志中的第一个单元格 运行 之后,刚启动笔记本会导致内核崩溃:

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 所需的最小配置。

运行 virtual framebuffer X server下的笔记本,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)