knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
library(capture)
{capure} allow to take screenshots in R Markdown documents in HTML format.
Capture a screenshot of the entire page with:
capture( selector = "body", filename = "my-document", "Take screenshot", button_class = "btn btn-primary btn-block" )
If you want a PDF as output, you can use capture_pdf()
.
For example, save the map as PNG:
capture("#map-and-code", "map", "Save map and code as PNG") capture("#only-map", "map", "Save only map as PNG")
::: {#map-and-code}
library(leaflet) leaflet(width = "100%", elementId = "only-map") %>% addTiles() %>% addMarkers(lng=174.768, lat=-36.852, popup="The birthplace of R")
:::
Or with a {dygraph} chart:
capture("#my-chart", "chart", "Save chart as PNG")
library(dygraphs) lungDeaths <- cbind(mdeaths, fdeaths) dygraph(lungDeaths, width = "100%", elementId = "my-chart")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.