огледало од https://git.sr.ht/~hrbrmstr/splashr
boB Rudis
пре 7 година
9 измењених фајлова са 141 додато и 57 уклоњено
@ -0,0 +1,31 @@ |
|||
#' Return the HTML or image (png) of the javascript-rendered page in a local file |
|||
#' |
|||
#' The suggested use-case for this is rendering a widget |
|||
#' |
|||
#' TODO Test if container is running |
|||
#' TODO Enable passing in of an htmlwidget and use saveWidget |
|||
#' |
|||
#' @md |
|||
#' @param splash_obj Object created by a call to [splash]() |
|||
#' @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]().** |
|||
#' @param output either `html` or `png` to get the page content or an image capture |
|||
#' @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. |
|||
#' @return An XML document or `magick` object |
|||
#' @export |
|||
render_file <- function(splash_obj, file_path, output=c("html", "png"), wait=0, viewport="1024x768") { |
|||
|
|||
output <- match.arg(output, c("html", "png")) |
|||
|
|||
file.copy(file_path, .pkgenv$temp_dir) |
|||
|
|||
fil <- basename(file_path) |
|||
|
|||
URL <- sprintf("http://localhost:9999/%s", fil) |
|||
|
|||
if (output == "html") { |
|||
render_html(splash_obj, URL, wait=wait, viewport=viewport) |
|||
} else { |
|||
render_png(splash_obj, URL, wait=wait, viewport=viewport) |
|||
} |
|||
|
|||
} |
@ -0,0 +1,6 @@ |
|||
.pkgenv <- new.env(parent=emptyenv()) |
|||
|
|||
.onAttach <- function(...) { |
|||
temp_dir <- normalizePath(gsub("//", "/", path.expand(tempdir()))) |
|||
assign("temp_dir", temp_dir, envir=.pkgenv) |
|||
} |
@ -0,0 +1,28 @@ |
|||
% Generated by roxygen2: do not edit by hand |
|||
% Please edit documentation in R/render_file.R |
|||
\name{render_file} |
|||
\alias{render_file} |
|||
\title{Return the HTML or image (png) of the javascript-rendered page in a local file} |
|||
\usage{ |
|||
render_file(splash_obj, file_path, output = c("html", "png"), wait = 0, |
|||
viewport = "1024x768") |
|||
} |
|||
\arguments{ |
|||
\item{splash_obj}{Object created by a call to \url{splash}} |
|||
|
|||
\item{file_path}{Absolute path to a filename on the local host. \strong{This only works with a locally running Splash instance started with \url{start_splash}.}} |
|||
|
|||
\item{output}{either \code{html} or \code{png} to get the page content or an image capture} |
|||
|
|||
\item{viewport}{View width and height (in pixels) of the browser viewport to render the web page. Format is "\code{<width>x<height>}". e.g. 800x600. Default value is 1024x768.} |
|||
} |
|||
\value{ |
|||
An XML document or \code{magick} object |
|||
} |
|||
\description{ |
|||
The suggested use-case for this is rendering a widget |
|||
} |
|||
\details{ |
|||
TODO Test if container is running |
|||
TODO Enable passing in of an htmlwidget and use saveWidget |
|||
} |
Loading…
Reference in new issue