forked from quarto-dev/quarto-r
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.R
41 lines (38 loc) · 1.2 KB
/
run.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#' Serve Interactive Document
#'
#' Serve a Shiny interactive document. By default, the document will
#' be rendered first and then served 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 serving it.
#'
#' @inheritParams quarto_preview
#'
#' @export
quarto_serve <- 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)
}