Reputation: 123
I have an image on disk and want to display it in a markdown cell in an R Jupyter Notebook. How can I go about this?
I know with Python this as simple as importing the Image class from display.
Upvotes: 12
Views: 8183
Reputation: 3093
Here is code for the Jupyter R Kernel Notebook User to select choose an image file (.PNG) from the file system, strip off the full pathname, and then insert the image into the cell below this code.
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.
Then use the standard Jupyter Notebook extension "Hide Input" to hide this codecell, and the "Freeze" NBextension to freeze the codecell so the image stays frozen and the notebook does not try to select and insert a new image everytime the notebook code runs.
Upvotes: 0
Reputation: 2319
IRdisplay has functions to rich display "stuff", which includes images:
library("IRdisplay")
display_png(file="plot.png)
Upvotes: 11
Reputation: 3263
In a markdown cell as you usually would in a Jupyter Python notebook:
<img src="../relative/path/to/img.png">
or

Upvotes: 3