Skip to content

dreamRs/capture

Repository files navigation

capture

Add a button in Shiny application or R Markdown document to take a screenshot (PNG or PDF) of a specified element. It uses html-to-image to convert DOM elements to PNG and jsPDF to generate PDF. Doesn't work in IE.

Lifecycle: experimental R-CMD-check

Installation

You can install the development version of {capture} from GitHub with:

remotes::install_github("dreamRs/capture")

Features

Take screenshots in your {shiny} applications and {rmarkdown} documents.

  • capture(): save as PNG
  • capture_pdf(): save as PDF

Example

In UI, use capture() to save element of the page as PNG:

fluidPage(

  capture::capture(
    selector = "body",
    filename = "all-page.png",
    icon("camera"), "Take screenshot of all page"
  )
  
  # ...
  
)

You can create PDF document of the page with capture_pdf().

Related packages

  • shinyscreenshot (on CRAN): Capture screenshots of entire pages or parts of pages in Shiny apps
  • snapper : snap images of html objects in Shiny apps using canvas2html JavaScript library.

Development

This package use {packer} to manage JavaScript assets, see packer's documentation for more.

Install nodes modules with:

packer::npm_install()

Modify srcjs/exts/image.js or srcjs/exts/pdf.js, then run:

packer::bundle()

Re-install R package and try capture() or capture_pdf() functions.