Debugging why my plots weren’t showing up in blogdown

While writing my last post, I discovered that while using blogdown::serve_site(), any plots generated by R code weren’t showing up in the website.

The first thing I did was remove the .gitignore file under my static directory. This unfortunately didn’t fix the issue (but I suspect was still a contributor to the final fix.)

The second thing I did was add a setup R chunk that had the code knitr::opts_chunk$set(echo = TRUE, fig.path = "static") in it. So for clarity, a chunk like

```{r setup}
knitr::opts_chunk$set(echo = TRUE, fig.path = "static")
```

right at the top of my page.

Once I added that, everything worked fine. I don’t really understand what’s going on here, but clearly my blog doesn’t realise that figures are being rendered to ‘static’, and we have to tell it to look there.

If anyone else is having this problem, I hope this helps.