History: Profile_r_test14_webshot
Source of version: 1
- «
- »
Copy to clipboard
! {{page}} 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: * https://cran.r-project.org/web/packages/webshot/vignettes/intro.html * https://github.com/wch/webshot {maketoc title="" levels="2,3"} !!# Installation {RR(echo=TRUE)} 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() } {RR} !!# Demo1 {RR(echo=TRUE, cacheby="pagename")} 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_{{page}}/mywebshot.png"}^ {RR} ^{img src="temp/cache/R_{{page}}/mywebshot.png"}^ !!# Demo2 {RR(echo=TRUE, cacheby="pagename")} 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_{{page}}/printtorture_data.png"}^ # ## Link to PDF file displayed below with # [temp/cache/R_{{page}}/printtorture.pdf|PDF] {RR} ^{img src="temp/cache/R_{{page}}/printtorture_data.png"}^ [temp/cache/R_{{page}}/printtorture.pdf|PDF]