Browse Source

README

master
boB Rudis 3 years ago
parent
commit
5df93a75e1
9 changed files with 114 additions and 17 deletions
  1. +3
    -0
      R/docker-splash.r
  2. +6
    -4
      R/render_file.R
  3. +42
    -0
      README.Rmd
  4. +58
    -11
      README.md
  5. BIN
      img/cap.jpg
  6. BIN
      img/cap.png
  7. BIN
      img/diag.png
  8. +3
    -1
      man/render_file.Rd
  9. +2
    -1
      man/start_splash.Rd

+ 3
- 0
R/docker-splash.r View File

@@ -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.


+ 6
- 4
R/render_file.R View File

@@ -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 "`<width>x<height>`". 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, ...)
}

}
}


+ 42
- 0
README.Rmd View File

@@ -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!

- <strike>Implement `render.json`</strike>
- <strike>Implement "file rendering"</strike>
- Implement `execute` (you can script Splash!)
- <strike>Add integration with [`HARtools`](https://github.com/johndharrison/HARtools)</strike>
- <strike>_Possibly_ writing R function wrappers to install/start/stop Splash</strike> 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}


+ 58
- 11
README.md View File

@@ -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!

- <strike>Implement `render.json`</strike>
- <strike>Implement "file rendering"</strike>
- Implement `execute` (you can script Splash!)
- <strike>Add integration with [`HARtools`](https://github.com/johndharrison/HARtools)</strike>
- <strike>*Possibly* writing R function wrappers to install/start/stop Splash</strike> 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}
## <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
## [1] <head>\n<script type="text/javascript" async="" id="tealium-tag-3005" src="http://b.scorecardresearch.com/c2/1526 ...
## [1] <head>\n<script src="http://widget-cdn.rpxnow.com/manifest/login?version=1.114.1_widgets_244" type="text/javascri ...
## [2] <body id="index-index" class="index-index" onload="findLinks('myLink');">\n\n\t<div id="page_frame" style="overfl ...

``` r
@@ -150,21 +154,21 @@ print(har)
## --------HAR PAGES--------
## Page id: 1 , Page title: Poynter – A global leader in journalism. Strengthening democracy.
## --------HAR ENTRIES--------
## Number of entries: 50
## Number of entries: 56
## REQUESTS:
## Page: 1
## Number of entries: 50
## Number of entries: 56
## - http://www.poynter.org/
## - http://www.poynter.org/wp-content/plugins/easy-author-image/css/easy-author-image.css?ver=2016_06_24.1
## - http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css?ver=2016_06_24.1
## - http://cloud.webtype.com/css/162ac332-3b31-4b73-ad44-da375b7f2fe3.css?ver=2016_06_24.1
## - http://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css?ver=2016_06_24.1
## ........
## - https://stats.g.doubleclick.net/r/collect?v=1&aip=1&t=dc&_r=3&tid=UA-2072784-1&cid=1992506909.1486267047&jid=1325...
## - http://srv-2017-02-05-03.config.parsely.com/config/poynter.org
## - http://srv-2017-02-05-03.pixel.parsely.com/plogger/?rand=1486267047731&idsite=poynter.org&url=http%3A%2F%2Fwww.po...
## - https://tpc.googlesyndication.com/simgad/10025351500812357522
## - https://securepubads.g.doubleclick.net/pcs/view?xai=AKAOjsv3IVwW6mP5Eu79tajcj_fXJXhJhWb5xWUMF31OW8pkuhKz-68Gbdb1m...
## - http://t.brand-server.com/adj?s=13281&sz=300x250&url=http://www.poynter.org/
## - https://securepubads.g.doubleclick.net/pcs/view?xai=AKAOjsvaVvbr_IQSstPhvzvsWpiYqUHChLUWRLAecmxq6py54Rs-i9aCMEuQR...
## - http://srv-2017-02-09-22.pixel.parsely.com/plogger/?rand=1486678060999&idsite=poynter.org&url=http%3A%2F%2Fwww.po...
## - http://os4m-d.openx.net/w/1.0/jstag?nc=102766797-YieldLift
## - https://securepubads.g.doubleclick.net/pcs/view?xai=AKAOjst2Xvpi5LxMyrFk9_Sw30O5JePbM44dE-0Z7WE046-IhfZcDs-NdDZQD...

You can use [`HARtools::HARviewer`](https://github.com/johndharrison/HARtools/blob/master/R/HARviewer.R) — which this pkg import/exports — to get view the HAR in an interactive HTML widget.

@@ -184,6 +188,49 @@ splash("splash", 8050L) %>%

![](img/cap.jpg)

### Rendering Widgets

``` r
splash_vm <- start_splash(add_tempdir=TRUE)
```

## f9f80950cd30b16c9209412d5578ff53b93b2492d578473ee34e67506014a20e

``` 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")
```

## {xml_document}
## <html>
## [1] <head>\n<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">\n<meta charset="utf-8">\n<script src= ...
## [2] <body style="background-color: white; margin: 0px; padding: 40px;">\n<div id="htmlwidget_container">\n<div id="ht ...

``` r
splash("localhost") %>%
render_file("/tmp/diag.html", output="png", wait=2)
```

![](img/diag.png)

``` r
stop_splash(splash_vm)
```

## f9f80950cd30

### Test Results

``` r
@@ -193,7 +240,7 @@ library(testthat)
date()
```

## [1] "Sat Feb 4 22:57:33 2017"
## [1] "Thu Feb 9 17:07:52 2017"

``` r
test_dir("tests/")


BIN
img/cap.jpg View File

Before After
Width: 1024  |  Height: 768  |  Size: 118KB Width: 1024  |  Height: 768  |  Size: 124KB

BIN
img/cap.png View File

Before After
Width: 1024  |  Height: 768  |  Size: 433KB Width: 1024  |  Height: 768  |  Size: 467KB

BIN
img/diag.png View File

Before After
Width: 1024  |  Height: 768  |  Size: 11KB

+ 3
- 1
man/render_file.Rd View File

@@ -5,7 +5,7 @@
\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")
viewport = "1024x768", ...)
}
\arguments{
\item{splash_obj}{Object created by a call to \url{splash}}
@@ -15,6 +15,8 @@ render_file(splash_obj, file_path, output = c("html", "png"), wait = 0,
\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.}

\item{...}{other params to \url{render_html} or \url{render_png}}
}
\value{
An XML document or \code{magick} object


+ 2
- 1
man/start_splash.Rd View File

@@ -20,7 +20,8 @@ will be added to the mount configuration for use with [render_file](). You will
`harbor` `container` object
}
\description{
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.
}
\note{
you need Docker running on your system and have pulled the container with


Loading…
Cancel
Save