Demo of the Webshot R package. Webshot makes it easy to take screenshots of web pages (all or sections of it defined by their css selectors) from R, and save them as png or pdf. It requires an installation of the external program PhantomJS (v2+). You may install phantomjs automatically through the provided function webshot::install_phantomjs(). ::.


Page contents:

1. Installation

if (!require(webshot)) {
install.packages("webshot", repos="https://ftp.heanet.ie/mirrors/cran.r-project.org/")

# You might also want to install the development version, if you need.
# if (!require(devtools)) { install.packages("devtools", repos="https://ftp.heanet.ie/mirrors/cran.r-project.org/") }

# You need to create first the folder "~/bin", which in this installation is "/var/www/bin/, since this is the place where phantomjs will be installed to and added to the PATH in GNU/Linux

2. Demo1

{RR(echo=TRUE, cacheby="pagename")}
website <- "http://rstudio.github.io/leaflet/"
outfilename.noext <- file.path(getwd(), "mywebshot")
  1. Might need a longer delay for all assets to display
webshot(website, paste0(outfilename.noext, ".png"), delay = 0.5)
webshot(website, paste0(outfilename.noext, ".pdf"), delay = 0.5) # Can also output to PDF
webshot(website, paste0(outfilename.noext, ".png"), selector = c("#features", "#installation"))

    1. Image embedded below in this wiki page with:
  1. Image


3. Demo2

{RR(echo=TRUE, cacheby="pagename")}
outfilename.noext <- file.path(getwd(), "printtorture")
webshot("http://trunk.notre.website/print-torture", paste0(outfilename.noext, ".png"))
webshot("http://trunk.notre.website/print-torture", paste0(outfilename.noext, ".pdf")) # Can also output to PDF
webshot("http://trunk.notre.website/print-torture", paste0(outfilename.noext, "_data.png"),
selector = "#page-data")

    1. Image embedded below in this wiki page with:
  1. Image
    1. Link to PDF file displayed below with
  2. PDF