9.3 Embed a web page

If you have the webshot2 package (Chang 2023) and Chrome 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.

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().

References

Chang, Winston. 2023. Webshot2: Take Screenshots of Web Pages. https://rstudio.github.io/webshot2/.
———. 2016. Bookdown: Authoring Books and Technical Documents with R Markdown. Boca Raton, Florida: Chapman; Hall/CRC. https://bookdown.org/yihui/bookdown.