Images not rendered properly using a 'learnr' Rmd wrapped in an R-package

Hi everyone,

I am writing with an issue I am having with rendering images for a 'learnr' tutorial I am currently working on.

When I made the tutorial in RMarkdown on my local device, everything worked as it should. I was able to include images using 'include_graphics()' and 'here()', and when knitting, these rendered as they expected. Then, to share the tutorial with my class, I followed this post to wrap it up in an R-package, which is now available on my GitHub.

Since the images now had to be installed with the R-package, I move them inside a folder called 'images' inside the 'inst' folder. I updated the path in the include_graphic(here(PATH)) command to where the images are now located in the R-package. I know this updated path works because I can load the images when I run the command inside RMarkdown (see screenshot top left). However, when I run the tutorial in RStudio (which I believe is done using Shiny? - screenshot top right), the images are suddenly not rendering anymore, but instead, give me one of those image icons (screenshot bottom).

I have no idea what is causing this to break since everything works as expected right until the moment I launch the tutorial. I have tried launching the tutorial both in the R-viewer and in the default browser, but the images are not rendering in both circumstances.

I appreciate any insights!

Thanks in advance,


Please see the External Resources section in the learnr documentation. In short, you should place images in an images/ folder next to the tutorial source .Rmd and reference them in the document using ![](images/cat.png) or knitr::include_graphics("images/cat.png").

There are more details in my answer to this question When can I use a prefix created with `shiny::addResourcePath()` to access shared resources? - #2 by grrrck

Edit: I think the missing piece for you is just that the images/ folder needs to be in the same folder where the tutorial is stored. Oh, and please don't use here::here() since that makes the path absolute when it needs to be a relative path.)

1 Like

I appreciate your quick response. I tried your suggestion and it fixed the problem!
Thanks a lot for your help.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.