Skip to content

Commit

Permalink
Specify notebook to render via CLI args (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
tschaffter authored May 19, 2021
1 parent babf579 commit 6d36500
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,8 @@ HTML notebook that will be saved to the same directory with the extension
docker run --rm \
--env-file .env \
-v $(pwd)/notebooks:/data \
-e RENDER_INPUT="/data/examples/notebook.Rmd" \
tschaffter/rstudio \
render
tschaffter/rstudio:4.0.5 \
render /data/examples/notebook.Rmd
```

## Versioning
Expand Down
10 changes: 7 additions & 3 deletions root/render.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
# Renders a notebook in HTML or PDF format using args specified as environment
# variables.
# Render an Rmd notebook to HTML or PDF.
#
# TODO: Use a library for managing command-line options.

input = Sys.getenv("RENDER_INPUT", unset = NA)
# input = Sys.getenv("RENDER_INPUT", unset = NA)
output_format = Sys.getenv("RENDER_OUTPUT_FORMAT", unset = "html_document")
quiet = Sys.getenv("RENDER_QUIET", unset = "TRUE")

options <- commandArgs(trailingOnly = TRUE)
input <- options[1]

if (is.na(input)) {
stop("The environment variable RENDER_INPUT is required")
}
Expand Down
4 changes: 3 additions & 1 deletion root/usr/local/bin/render
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash
#
# Render an Rmd notebook to HTML or PDF.

set -euo pipefail

Rscript /render.R
Rscript /render.R "$@"

0 comments on commit 6d36500

Please sign in to comment.