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

在R Jupyter笔记本中显示文件中的图像,r,jupyter,jupyter-notebook,jupyter-irkernel,R,Jupyter,Jupyter Notebook,Jupyter Irkernel,我在磁盘上有一个图像,我想把它显示在Rjupyter笔记本的一个标记单元格中。我该怎么办 我知道使用Python可以很简单地从display导入Image类。在标记单元格中,就像在Jupyter Python笔记本中一样: <img src="../relative/path/to/img.png"> IRdisplay具有丰富显示“素材”的功能,其中包括图像: library("IRdisplay") display_png(file="plot.png) 下面是Jupyt

我在磁盘上有一个图像,我想把它显示在Rjupyter笔记本的一个标记单元格中。我该怎么办


我知道使用Python可以很简单地从display导入Image类。

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

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

IRdisplay具有丰富显示“素材”的功能,其中包括图像:

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

下面是Jupyter R内核笔记本用户从文件系统中选择图像文件(.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笔记本扩展名“Hide Input”隐藏此编码单元,使用“Freeze”NBextension冻结编码单元,以便图像保持冻结状态,并且笔记本不会每次运行笔记本代码时都尝试选择和插入新图像

这似乎只适用于来自web的图像,而不适用于本地托管的图像images@user3617525,如果您为图像提供了有效的相对路径,则此操作应该有效。我喜欢语法
![图片](../relative/path/to/img.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.