diff --git a/R/docker-splash.r b/R/docker-splash.r index 3c967e2..a7d8c8b 100644 --- a/R/docker-splash.r +++ b/R/docker-splash.r @@ -15,6 +15,9 @@ install_splash <- function(host = harbor::localhost) { #' Start a Splash server Docker container #' +#' If using this in an automation context, you should consider adding a +#' `Sys.sleep(3)` (or higher) after starting the docker container. +#' #' @param host Docker host; defauolts to `localhost` #' @param add_tempdir This is `FALSE` initially since you could try to run #' the splash image on a remote system. It has to be a local one for this to work. diff --git a/R/render_file.R b/R/render_file.R index c986e58..b1f7cde 100644 --- a/R/render_file.R +++ b/R/render_file.R @@ -10,9 +10,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]().** #' @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 "`x`". e.g. 800x600. Default value is 1024x768. +#' @param ... other params to [render_html]() or [render_png]() #' @return An XML document or `magick` object #' @export -render_file <- function(splash_obj, file_path, output=c("html", "png"), wait=0, viewport="1024x768") { +render_file <- function(splash_obj, file_path, output=c("html", "png"), wait=0, viewport="1024x768", ...) { output <- match.arg(output, c("html", "png")) @@ -23,9 +24,10 @@ render_file <- function(splash_obj, file_path, output=c("html", "png"), wait=0, URL <- sprintf("http://localhost:9999/%s", fil) if (output == "html") { - render_html(splash_obj, URL, wait=wait, viewport=viewport) + render_html(splash_obj, URL, wait=wait, viewport=viewport, ...) } else { - render_png(splash_obj, URL, wait=wait, viewport=viewport) + render_png(splash_obj, URL, wait=wait, viewport=viewport, ...) } -} \ No newline at end of file +} + diff --git a/README.Rmd b/README.Rmd index d8cefd9..5b046bf 100644 --- a/README.Rmd +++ b/README.Rmd @@ -39,6 +39,7 @@ All you need for this package to work is a running Splash instance. You provide The following functions are implemented: - `render_html`: Return the HTML of the javascript-rendered page. +- `render_file`: Return the HTML or image (png) of the javascript-rendered page in a local file - `render_har`: Return information about Splash interaction with a website in [HAR](http://www.softwareishard.com/blog/har-12-spec/) format. - `render_jpeg`: Return a image (in JPEG format) of the javascript-rendered page. - `render_png`: Return a image (in PNG format) of the javascript-rendered page. @@ -54,6 +55,7 @@ Some functions from `HARtools` are imported/exported and `%>%` is imported/expor Suggest more in a feature req! - Implement `render.json` +- Implement "file rendering" - Implement `execute` (you can script Splash!) - Add integration with [`HARtools`](https://github.com/johndharrison/HARtools) - _Possibly_ writing R function wrappers to install/start/stop Splash which would also support enabling javascript profiles, request filters and proxy profiles from with R directly, using [`harbor`](https://github.com/wch/harbor) @@ -77,6 +79,8 @@ library(magick) library(rvest) library(anytime) library(hrbrmisc) # github +library(htmlwidgets) +library(DiagrammeR) library(tidyverse) # current verison @@ -137,6 +141,44 @@ splash("splash", 8050L) %>% ![](img/cap.jpg) +### Rendering Widgets + +```{r} +splash_vm <- start_splash(add_tempdir=TRUE) +``` + +```{r include=FALSE, echo=FALSE} +Sys.sleep(3) +``` + +```{r} +DiagrammeR(" + graph LR + A-->B + A-->C + C-->E + B-->D + C-->D + D-->F + E-->F +") %>% + saveWidget("/tmp/diag.html") + +splash("localhost") %>% + render_file("/tmp/diag.html", output="html") +``` + +```{r eval=FALSE} +splash("localhost") %>% + render_file("/tmp/diag.html", output="png", wait=2) +``` + +![](img/diag.png) + +```{r} +stop_splash(splash_vm) +``` + ### Test Results ```{r message=FALSE, warning=FALSE, error=FALSE} diff --git a/README.md b/README.md index 7ffc5d5..866122f 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,7 @@ All you need for this package to work is a running Splash instance. You provide The following functions are implemented: - `render_html`: Return the HTML of the javascript-rendered page. +- `render_file`: Return the HTML or image (png) of the javascript-rendered page in a local file - `render_har`: Return information about Splash interaction with a website in [HAR](http://www.softwareishard.com/blog/har-12-spec/) format. - `render_jpeg`: Return a image (in JPEG format) of the javascript-rendered page. - `render_png`: Return a image (in PNG format) of the javascript-rendered page. @@ -51,6 +52,7 @@ Some functions from `HARtools` are imported/exported and `%>%` is imported/expor Suggest more in a feature req! - Implement `render.json` +- Implement "file rendering" - Implement `execute` (you can script Splash!) - Add integration with [`HARtools`](https://github.com/johndharrison/HARtools) - *Possibly* writing R function wrappers to install/start/stop Splash which would also support enabling javascript profiles, request filters and proxy profiles from with R directly, using [`harbor`](https://github.com/wch/harbor) @@ -74,6 +76,8 @@ library(magick) library(rvest) library(anytime) library(hrbrmisc) # github +library(htmlwidgets) +library(DiagrammeR) library(tidyverse) # current verison @@ -87,7 +91,7 @@ splash("splash", 8050L) %>% splash_active() ``` - ## Status of splash instance on [http://splash:8050]: ok. Max RSS: 412110848 + ## Status of splash instance on [http://splash:8050]: ok. Max RSS: 462295040 ``` r splash("splash", 8050L) %>% @@ -103,7 +107,7 @@ splash("splash", 8050L) %>% ## ..$ LuaRuntime: int 1 ## ..$ QTimer : int 1 ## ..$ Request : int 1 - ## $ maxrss : int 402452 + ## $ maxrss : int 451460 ## $ qsize : int 0 ## $ url : chr "http://splash:8050" ## - attr(*, "class")= chr [1:2] "splash_debug" "list" @@ -118,7 +122,7 @@ splash("splash", 8050L) %>% ## {xml_document} ## - ## [1] \n