如何在没有显示器的机器上运行带有内联图形的jupyter Rkernel笔记本?

jvd*_*d10 1 linux x11 r jupyter-notebook jupyter-irkernel

我经常在没有 X11 的 Linux 集群计算节点上运行 jupyter IPython 笔记本,没有任何问题。然而,在相同的设置上运行 R 内核效果不佳。

机器详细信息如下:

  • CentOS 7.2
  • R 3.3.1 具有 X11、png 和 cairo 功能
  • 蟒蛇 4.0.0(蟒蛇2.7.11)

在第一个单元运行后,仅启动笔记本就会导致内核崩溃,并在日志中显示以下内容:

unable to open connection to X11 display ''
Run Code Online (Sandbox Code Playgroud)

我可以通过启动笔记本来让它工作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
Run Code Online (Sandbox Code Playgroud)

我想如果我可以安装 x11 字体,它就可以工作,但这是在集群的计算节点上,我没有安装它们的管理权限。

在没有 X11 的 Linux 机器上配置带有 R 内核的 jupyter 笔记本以生成图形的正确方法是什么?

jvd*_*d10 5

我认为我已经找到了在没有显示硬件和物理输入设备的 Linux 计算机上运行笔记本电脑时 irkernel 所需的最低配置。

在虚拟帧缓冲区 X 服务器xvfb下运行笔记本:

xvfb-run jupyter notebook
Run Code Online (Sandbox Code Playgroud)

使用cairo代替 X11:

# Run this in a notebook cell, or put in .Rprofile
options(bitmapType="cairo")
Run Code Online (Sandbox Code Playgroud)

设置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)
Run Code Online (Sandbox Code Playgroud)