在 R Jupyter 笔记本中显示来自文件的图像

Display Images from file in R Jupyter notebook

我在磁盘上有一张图片,想在 R Jupyter Notebook 的降价单元格中显示它。我该怎么做?

我知道 Python 这就像从显示器导入图像 class 一样简单。

在 Markdown 单元格中,就像在 Jupyter Python 笔记本中一样:

<img src="../relative/path/to/img.png">

![image](../relative/path/to/img.png)

IRdisplay 具有丰富的显示功能 "stuff",其中包括图像:

library("IRdisplay")
display_png(file="plot.png)  

这是 Jupyter R 内核笔记本用户 select 从文件系统中选择一个图像文件 (.PNG),去掉完整路径名,然后将图像插入到此下方的单元格中的代码代码。

image_chosen = choose.files(
               default = "", 
               caption = "Select The Image File (in PNG format) to Insert",
               multi = TRUE, filters = Filters,
               index = nrow(Filters)
               )

chosen_image_name = basename(image_chosen)
#chosen_image_name   # uncomment this line to show the location of the image.

IRdisplay::display_png(file = chosen_image_name)    # This line inserts the image.

然后使用标准的 Jupyter Notebook 扩展 "Hide Input" 隐藏此代码单元,并使用 "Freeze" NBextension 冻结代码单元,使图像保持冻结状态,笔记本不会尝试 select 并在每次笔记本代码运行时插入一个新图像。