如何在 Jupyter 笔记本的 R 输出中显示 table 个图像?

How to display a table of images in R output in a Jupyter notebook?

如何获取图像 URL 列表,并将它们显示在具有 R 内核的 Jupyter 笔记本中的 HTML table 中?

这是一个 URL 列表:

image_urls = c('https://i.stack.imgur.com/wdQNM.jpg',
  'https://i.stack.imgur.com/8oysP.jpg')

下面是一些代码,用于显示 image_url 中的一张图片:

library(jpeg)
library(RCurl)

img <- RCurl::getBinaryURL(image_url)
jj <- jpeg::readJPEG(img,native=TRUE)
plot(0:1,0:1,type="n",ann=FALSE,axes=FALSE)
rasterImage(jj,0,0,1,1)

Edit:另一种思考方式是,是否有像 ipython 的 display 这样的功能?看起来 https://github.com/IRkernel/repr 中可能有。我要多读书。

我是所有 IRkernel 相关项目的维护者。

IRdisplay is the package you’re searching for, specifically display_jpeg:

library(IRdisplay)
display_jpeg(file = 'filename.jpg')

遗憾的是 file 参数不适用于 URL(目前),因此您必须手动将数据传递给它:

jpeg_data <- RCurl::getBinaryURL(image_url)
display_jpeg(jpeg_data)