12.1 Bookdown Insert Image From URL


With multiple output targets, such as html and latex, we need a little care in ensuring each is supported. A common use case is to include an image from a specific URL with the html document. This is accomplished with markdown:


However for latex output the path is expected to be a local path to the image file. Instead we can utilise knitr::include_url():

 if (knitr::is_html_output())
 } else {

This might be included in an R code block that begins with:

{r echo=FALSE, fig.align="left", out.width="50%"}

An image can be resized:


Your donation will support ongoing availability and give you access to the PDF version of this book. Desktop Survival Guides include Data Science, GNU/Linux, and MLHub. Books available on Amazon include Data Mining with Rattle and Essentials of Data Science. Popular open source software includes rattle, wajig, and mlhub. Hosted by Togaware, a pioneer of free and open source software since 1984. Copyright © 1995-2022 Graham.Williams@togaware.com Creative Commons Attribution-ShareAlike 4.0