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.

67 lines
2.3 KiB

#' Retrieve the Docker image for Splash
#'
#' @md
#' @param host Docker host; defauolts to `localhost`
#' @return `harbor` `host` object
#' @export
#' @examples \dontrun{
#' install_splash()
#' splash_container <- start_splash()
#' stop_splash(splash_container)
#' }
install_splash <- function(host = harbor::localhost) {
6 years ago
harbor::docker_pull(host, "hrbrmstr/splashttpd")
}
#' Start a Splash server Docker container
#'
#' @param host Docker host; defauolts to `localhost`
6 years ago
#' @param add_tempdir if `TRUE` then a local temporary directory (made with [tempdir]())
#' will be added to the mount configuration for use with [render_file](). You will need to
#' ensure the necessary system temp dirs are accessible as a mounts. For
#' macOS this means adding `/private` to said Docker config.
#' @note you need Docker running on your system and have pulled the container with
#' [install_spash] for this to work. You should save the resultant `host`
#' object for use in [stop_splash].
#' @return `harbor` `container` object
#' @export
#' @examples \dontrun{
#' install_splash()
#' splash_container <- start_splash()
#' stop_splash(splash_container)
#' }
6 years ago
start_splash <- function(host = harbor::localhost, add_tempdir=TRUE) {
doc_opts <- c("-p", "5023:5023",
"-p", "8050:8050",
"-p", "8051:8051")
if (add_tempdir)
doc_opts <- c(doc_opts,
sprintf("--volume=%s", sprintf("%s:/splashfiles", .pkgenv$temp_dir)))
# purrr::walk(doc_opts, message)
harbor::docker_run(host,
6 years ago
image = "hrbrmstr/splashttpd",
detach = TRUE,
6 years ago
docker_opts = doc_opts)
}
#' Stop a running a Splash server Docker container
#'
#' @param splash_container saved Splash container id from [start_splash]
#' @param splash_container Docker `container` object created by [start_splash]
#' @note you need Docker running on your system and have pulled the container with
#' [install_spash] and started the Splash container with [start_splash] for this
#' to work. You will need the `container` object from [start_splash] for this to work.
#' @export
#' @examples \dontrun{
#' install_splash()
#' splash_container <- start_splash()
#' stop_splash(splash_container)
#' }
stop_splash <- function(splash_container) {
harbor::container_rm(splash_container, force=TRUE)
}