r - 如何在没有显示器的机器上运行带有内联图形的 jupyter Rkernel notebook?

标签 r linux x11 jupyter-notebook jupyter-irkernel

我经常在没有 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/

相关文章:

linux - 使用剪贴板跟踪 x11 中的复制粘贴

java - R 和 Java + WEKA 在计算最近邻方面的差异

r - mclapply 随机返回 NULL

mysql - 在 bash 脚本中运行 mysql 命令,无需登录或在每个命令中添加 -u root

c++ - X 的错误处理程序抛出异常是否安全?

不使用窗口管理器时 X11 无法最大化应用程序

r - 链接颜色与整数ggplot2

r - 与 data.table 进行 "fuzzy"和非模糊多对一合并

linux - Linux 中的 DMA memcpy 操作

Android Studio 模拟器无法在 Linux 中的代理服务器后面连接到 Internet