9.3 Embed a web page

If you have the webshot package (Chang 2019) and PhantomJS installed (see Section 9.2), you can embed any web page in the output document through knitr::include_url(). When you pass a URL of a web page to this function in a code chunk, it will generate an <iframe> (inline frame) if the output format is HTML, and a screenshot of the web page for other output formats. You can view the actual page in the inline frame. For example, Figure 9.1 should show you my homepage if you are reading the online version of this book, otherwise you will see a static screenshot instead.


FIGURE 9.1: Embed Yihui’s homepage as an iframe or screenshot.

Most chunk options related to figures also work for knitr::include_url(), such as out.width and fig.cap.

If you have published a Shiny app publicly on a server, you can use knitr::include_app() to include it, which works in the same way as include_url(). Section 2.11 of the bookdown book (Xie 2016) contains more details about include_app() and include_url().


Chang, Winston. 2019. Webshot: Take Screenshots of Web Pages. https://github.com/wch/webshot/.

Xie, Yihui. 2016. Bookdown: Authoring Books and Technical Documents with R Markdown. Boca Raton, Florida: Chapman; Hall/CRC. https://github.com/rstudio/bookdown.