new_app: Create or stop a local web application

View source: R/app.R

new_appR Documentation

Create or stop a local web application

Description

Create a local web application based on R's internal httpd.

Usage

new_app(name, handler, open = interactive(), host = "127.0.0.1", port = NULL)

stop_app(name = names(.proxy$apps))

Arguments

name

App name (a character string). Use name = '' to serve the app at the root URL ⁠http://host:PORT/⁠ via the proxy. If name is non-empty, the app is served directly by R's internal httpd at ⁠/custom/name/⁠. Each name must be unique; calling new_app() with an existing name replaces that app. For stop_app(), a character vector of app names to stop; defaults to all running apps.

handler

A function with signature ⁠function(path, query, post, headers)⁠ that handles HTTP requests and returns a response list.

open

Whether to open the app URL in a browser, or a function to open it. In non-interactive sessions this also controls whether the call blocks: passing open = FALSE explicitly suppresses both browser-opening and blocking.

host

Bind address for the proxy ("127.0.0.1" or "0.0.0.0"). Only used when name = ''.

port

Candidate proxy ports when name = ''. The first available port is selected (falling back to random_port() if needed). Ignored when name != ''.

Details

new_app() has two modes:

  • name = '': start an app behind a lightweight proxy at ⁠http://host:PORT/⁠, forwarding to R's internal httpd path ⁠/custom/xfun:PORT/⁠.

  • name != '': register a legacy app directly on R's internal httpd at ⁠http://127.0.0.1:BACKEND/custom/name/⁠ (compatible with older versions).

stop_app() deregisters one or more running apps.

Value

new_app() returns the app URL invisibly. stop_app() returns nothing.


xfun documentation built on June 19, 2026, 9:06 a.m.