Debian Codegraph @

man/new_app.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/app.R
3 \name{new_app}
4 \alias{new_app}
5 \alias{stop_app}
6 \title{Create or stop a local web application}
7 \usage{
8 new_app(name, handler, open = interactive(), host = "127.0.0.1", port = NULL)
9
10 stop_app(name = names(.proxy$apps))
11 }
12 \arguments{
13 \item{name}{App name (a character string). Use \code{name = ''} to serve the app
14 at the root URL \verb{http://host:PORT/} via the proxy. If \code{name} is non-empty,
15 the app is served directly by R's internal httpd at \verb{/custom/name/}. Each
16 name must be unique; calling \code{new_app()} with an existing name replaces
17 that app. For \code{stop_app()}, a character vector of app names to stop;
18 defaults to all running apps.}
19
20 \item{handler}{A function with signature \verb{function(path, query, post, headers)} that handles HTTP requests and returns a response list.}
21
22 \item{open}{Whether to open the app URL in a browser, or a function to open
23 it. In non-interactive sessions this also controls whether the call
24 blocks: passing \code{open = FALSE} explicitly suppresses both browser-opening
25 and blocking.}
26
27 \item{host}{Bind address for the proxy (\code{"127.0.0.1"} or \code{"0.0.0.0"}). Only
28 used when \code{name = ''}.}
29
30 \item{port}{Candidate proxy ports when \code{name = ''}. The first available port
31 is selected (falling back to \code{\link[=random_port]{random_port()}} if needed). Ignored when
32 \code{name != ''}.}
33 }
34 \value{
35 \code{new_app()} returns the app URL invisibly. \code{stop_app()} returns
36 nothing.
37 }
38 \description{
39 Create a local web application based on R's internal httpd.
40 }
41 \details{
42 \code{new_app()} has two modes:
43 \itemize{
44 \item \code{name = ''}: start an app behind a lightweight proxy at
45 \verb{http://host:PORT/}, forwarding to R's internal httpd path
46 \verb{/custom/xfun:PORT/}.
47 \item \code{name != ''}: register a legacy app directly on R's internal httpd at
48 \verb{http://127.0.0.1:BACKEND/custom/name/} (compatible with older versions).
49 }
50
51 \code{stop_app()} deregisters one or more running apps.
52 }