Skip to content

Commit

Permalink
add quarto_run function
Browse files Browse the repository at this point in the history
  • Loading branch information
jjallaire committed Aug 3, 2021
1 parent 97858db commit c55b0f9
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 3 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export(quarto_publish_app)
export(quarto_publish_doc)
export(quarto_publish_site)
export(quarto_render)
export(quarto_run)
export(quarto_serve)
export(quarto_serve_stop)
importFrom(jsonlite,fromJSON)
Expand Down
44 changes: 44 additions & 0 deletions R/run.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#' Run Interactive Document
#'
#' Run a Shiny interactive document. By default, the document will
#' be rendered first and then run. If you have previously rendered
#' the document, pass `render - FALSE` to skip rendering.
#'
#' @param input The input file to run. Should be a file with
#' a `server: shiny` entry in its YAML front-matter.
#' @param render Render the document before running it.
#'
#' @inheritParams quarto_serve
#'
#' @export
quarto_run <- function(input,
render = TRUE,
port = getOption("shiny.port"),
host = getOption("shiny.host", "127.0.0.1"),
browse = TRUE) {

# render if requested
if (render) {
quarto_render(input)
}

# build shiny args
shiny_args <- list(
port = port,
host = host,
launch.browser = browse
)

# we already ran quarto_render before the call to run
# so disable rendering
restore <- Sys.getenv("RMARKDOWN_RUN_PRERENDER", unset = NA)
Sys.setenv(RMARKDOWN_RUN_PRERENDER = "0")
if (!is.na(restore)) {
on.exit(Sys.setenv(RMARKDOWN_RUN_PRERENDER = restore), add = TRUE)
}

# run the doc
rmarkdown::run(input, shiny_args = shiny_args)
}


2 changes: 1 addition & 1 deletion R/serve.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#' format for the site.
#' @param port Port to listen on (defaults to 4848)
#' @param host Hostname to bind to (defaults to 127.0.0.1)
#' @param browse Open a browser to preview the site. Defaults to using the
#' @param browse Open a browser to preview the content. Defaults to using the
#' RStudio Viewer when running within RStudio.Pass a function (e.g.
#' `utils::browseURL` to override this behavior).
#' @param watch Watch for changes and automatically reload browser.
Expand Down
2 changes: 1 addition & 1 deletion man/quarto_preview.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions man/quarto_run.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/quarto_serve.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c55b0f9

Please sign in to comment.