hrbrmstr / splashr

:sweat_drops: Tools to Work with the 'Splash' JavaScript Rendering Service in R
Other
98 stars 5 forks source link

Ability to access htmlwidgets, local HTMLs #2

Closed bhaskarvk closed 7 years ago

bhaskarvk commented 7 years ago

It would be awesome if we can have

For all these the biggest inhibitor is that splash is running inside a docker container, so need a way to mount local files.

It'll also be nice if render_* can connect to host's loopback somehow. So we can also use http://localhost:... URLs, where localhost is the host not the docker image.

hrbrmstr commented 7 years ago

Once I code up the ability to config the docker instance we can have a /widget (or something) dir that the widget HTML files get shoved to and then automagically pass a file:/// URI to Splash (assuming it takes file URIs which it should). spiffy idea!

hrbrmstr commented 7 years ago

ARGH. It does not support file:// URIs BUT it's prbly doable to fire up another internal web server in the container (or use the existing one) and have it point to a mounted directory.

bhaskarvk commented 7 years ago

devd ?

hrbrmstr commented 7 years ago

hahahaha. I literally just began to test that

hrbrmstr commented 7 years ago

I cld also fire up a local web server (on the host) and point splash to it (just tried that too)

bhaskarvk commented 7 years ago

meaning on a non-loopback interface ? Not straightforward to connect to host services running on loopback, no? In any case it would go a long way in being able to do some unit/integration tests on widgets.

hrbrmstr commented 7 years ago

ok, so I made a new Docker image that also starts up an internal web server in the image (using python simplehttpserver). It looks for files in an internal mount point. I modified start_splash and some other functions to automatically mount a local os temp dir into the docker vm. You have to call start_splash() with add_tempdir=TRUE for that to work.

You may need to modify:

image

on macOS to ensure /private is shared/accessible.

Once all that is done, then you can call the new render_file():

render_file <- function(splash_obj, file_path, output=c("html", "png"), wait=0, viewport="1024x768") …

file_path is the path to the HTML file you want to render. Choose html to get XML back and png to get PNG back and modify wait and viewport accordingly.

It'll copy the file over to the tempdir and mangle a new URL for Splash to render.

I tested it with a cpl HTMLs from Rmds and it seems to work fine but this was just hacked together in abt 10m so YMMV.

NOTE: you absolutely need to re-run install_splash() as it picks up the new image from my docker hub.

hrbrmstr commented 7 years ago

Will re-open if it breaks