Blogdown Images Fail to Render on Site/Viewer

Hi,

This is my first time asking a question in the community so I hope I am doing it right!

I am trying to create my Blogdown site and I have used all options to attempt to create an image but it keeps failing to display in the viewer. Having followed the other advice on this web page, I have read the Blogdown book to try and troubleshoot it but am having some issues.

When I type this into my RMarkdown document as suggested, the image appears in the RMarkdown document, but it does not appear in the viewer (even after using addins > serve site).

I have also tried to use knitr's include_graphics function but the same image as above also appears.

knitr::include_graphics("C:/Users/chfal/Documents/blog/static/img.jpeg).

I can provide more information if needed, I wasn't sure what else to include because this is my first time asking a question. Thank you!

CHF

If I'm remembering correctly, I don't think you should need to write out the whole path to the image if it is in the static folder. Instead, try including only the part of the path "beyond" the static folder.

For example, I included a plot in a blog post from a saved image that was in a folder called img within static. My code for this:

knitr::include_graphics("/img/2017-12-21_bad_residual_plot.png")

In your case I think you could try

knitr::include_graphics("/img.jpeg")

See if that changes anything. :slightly_smiling_face:

2 Likes

Hi aosmith! Thanks for your response! This actually did work. I was referencing the static folder and I think that was the issue.

CHF

@aosmith is right. Hugo assumes that all your images are either in static/ or if you are using the newer page bundles, that the image is in the folder with your content. This is why relative file paths are necessary- you were trying to use absolute file paths instead.

Option 1: Static

Option 2: Page bundles

4 Likes

This works! Thank you so much for your help!

This topic was automatically closed 21 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.