r_test14_webshot
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() ::.See:
Contents of this page:
1.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/") } #devtools::install_github("wch/webshot") # 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 webshot::install_phantomjs() }
1.2. Demo1
require(webshot) website <- "http://rstudio.github.io/leaflet/" outfilename.noext <- file.path(getwd(), "mywebshot") # 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")) ## Image embedded below in this wiki page with: # ^{img src="temp/cache/R_r_test14_webshot/mywebshot.png"}^
NULL NULL NULL
1.3. Demo2
library(webshot) 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") ## Image embedded below in this wiki page with: # ^{img src="temp/cache/R_r_test14_webshot/printtorture_data.png"}^ # ## Link to PDF file displayed below with # [temp/cache/R_r_test14_webshot/printtorture.pdf|PDF]
NULL NULL NULL