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.

35 lines
1.3KB

  1. #' Return the HTML or image (png) of the javascript-rendered page in a local file
  2. #'
  3. #' The suggested use-case for this is rendering a widget
  4. #'
  5. #' TODO Test if container is running
  6. #' TODO Enable passing in of an htmlwidget and use saveWidget
  7. #'
  8. #' @md
  9. #' @param splash_obj Object created by a call to [splash()]
  10. #' @param file_path Absolute path to a filename on the local host. **This only works with a locally running Splash instance started with [start_splash]().**
  11. #' @param wait seconds to wait
  12. #' @param output either `html` or `png` to get the page content or an image capture
  13. #' @param viewport View width and height (in pixels) of the browser viewport to render the web page. Format is "`<width>x<height>`". e.g. 800x600. Default value is 1024x768.
  14. #' @param ... other params to [render_html()] or [render_png()]
  15. #' @return An XML document or `magick` object
  16. #' @export
  17. render_file <- function(splash_obj = splash_local, file_path, output=c("html", "png"), wait=0, viewport="1024x768", ...) {
  18. output <- match.arg(output, c("html", "png"))
  19. file.copy(file_path, .pkgenv$temp_dir)
  20. fil <- basename(file_path)
  21. URL <- sprintf("http://localhost:9999/%s", fil)
  22. if (output == "html") {
  23. render_html(splash_obj, URL, wait=wait, viewport=viewport, ...)
  24. } else {
  25. render_png(splash_obj, URL, wait=wait, viewport=viewport, ...)
  26. }
  27. }