Tools to Work with the 'Splash' JavaScript Rendering Service in R
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
1.1KB

  1. #' Return a image (in PNG format) of the javascript-rendered page.
  2. #'
  3. #' @md
  4. #' @param width,height Resize the rendered image to the given width/height (in pixels) keeping the aspect ratio.
  5. #' @param render_all If `TRUE` extend the viewport to include the whole webpage (possibly very tall) before rendering. Default is `FASLE`
  6. #' @inheritParams render_html
  7. #' @export
  8. render_png <- function(splash_obj, url, base_url=NULL, width=1024, height=768, render_all=FALSE,
  9. timeout=30, resource_timeout=NULL, wait=0,
  10. proxy, js, js_src, filters, allowed_domains="", allowed_content_types="",
  11. forbidden_content_types="", viewport="1024x768", images, headers, body,
  12. http_method, save_args, load_args) {
  13. res <- httr::GET(splash_url(splash_obj), path="render.png",
  14. encode="json",
  15. query=list(url=url, timeout=timeout, wait=wait, viewport=viewport,
  16. width=width, height=height, render_all=as.numeric(render_all)))
  17. httr::stop_for_status(res)
  18. magick::image_read(httr::content(res, as="raw"))
  19. }