Skip to contents

Launches deckifyr serve in the bundled Python engine as a background process via processx – deliberately not .run_deckifyr_cli(), which blocks until its subprocess exits and would hang forever against a long-running server. Waits for the server to accept connections (up to timeout seconds), then optionally opens its URL in a browser. Requires the optional web extra (fastapi/uvicorn) to be installed in deckifyr's bundled Python environment; if it isn't, the server process exits immediately and that failure is surfaced with its captured stderr rather than a generic timeout.

Usage

deck_serve(
  project = ".",
  host = "127.0.0.1",
  port = 8000,
  presentation = "presentation.yaml",
  open_browser = TRUE,
  timeout = 15,
  force = FALSE,
  rscript_bin = NULL,
  quarto_bin = NULL,
  soffice_bin = NULL,
  trusted_binaries_only = FALSE,
  allow_outside_project = FALSE
)

Arguments

project

Path to the project directory to serve. Default ".".

host

Host to bind. Default "127.0.0.1".

port

Port to bind. Default 8000.

presentation

presentation.yaml path, relative to project. Default "presentation.yaml".

open_browser

Open the server's URL once it's reachable – via the RStudio Viewer pane when running inside RStudio, otherwise the system default browser. Default TRUE.

timeout

Seconds to wait for the server to become reachable before giving up and killing the orphaned process. Default 15.

force

If host:port is already occupied by another deckifyr server, kill it first instead of erroring. Never kills a process that doesn't look like a deckifyr server, force or not. Default FALSE.

rscript_bin, quarto_bin, soffice_bin

Run this executable instead of whatever presentation.yaml's build.reportifyr.flextable.binary, build.quarto.binary or build.preview.binary says (NULL, the default, keeps the project file's own setting). For a launcher that treats project files as untrusted user data (deckifyr.policy).

trusted_binaries_only

If TRUE, a project file that names a non-default binary (and no override was given for it) fails with E_UNTRUSTED_BINARY before anything runs, and design.base, layouts, build.output, build.manifest and build.reportifyr's paths must stay inside the project (E_PATH_OUTSIDE_PROJECT). Default FALSE: existing projects behave exactly as before.

allow_outside_project

With trusted_binaries_only = TRUE, let those paths resolve outside the project (e.g. a shared organization design). Default FALSE.

Value

A deckifyr_server object (a list with class "deckifyr_server"): process (the processx::process), host, port, url, and project. Pass it to deck_stop_server() to shut the server down.

Details

Refuses to launch at all if host:port is already occupied (.port_is_open()), rather than proceeding and letting .wait_for_server()'s readiness poll connect to whatever is already there. This is a real, confirmed failure mode, not a hypothetical: a deckifyr_server handle whose process tree wasn't fully torn down (fixed alongside this check – .launch_server_process() now sets cleanup_tree = TRUE and deck_stop_server() calls kill_tree(), since uv run -m deckifyr serve is a real parent/child pair and killing only the tracked uv PID left the actual Python/uvicorn child running, orphaned, still bound to the port) left an old server listening on the default port; a second deck_serve() call at the same default port then had its own new process fail to bind (address already in use) while .wait_for_server() still reported success – because it was reconnecting to the old, stale server the whole time, not the new one – silently pointing the caller at the wrong project with no error at all.

force = TRUE additionally handles the port already being occupied by an existing deckifyr server (as opposed to a genuinely unrelated process, which it never touches, force or not): it looks up the occupant by port (.pids_listening_on_port()), confirms its command line actually looks like a deckifyr server (.pid_looks_like_deckifyr_server()), and kills it before proceeding – the same "stop by port" mechanism deck_stop_server() exposes directly, useful here specifically because the deckifyr_server handle for that old server may no longer exist (a fresh R session, or one where the object was simply lost) even though the process itself is still running.

Examples

if (FALSE) { # \dontrun{
server <- deck_serve(project = "my-deck")
deck_stop_server(server)

# Restart on the same port without first tracking down the old handle:
server <- deck_serve(project = "my-deck", force = TRUE)
} # }