9.3 Embed a web page
If you have the webshot package (Chang 2023) 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.
::include_url("https://yihui.org") knitr
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()
.