ricochet
Josiah ParryJosiah Parry

Simplifying app deployment in R

Understanding the _server.yml standard.

Deploying web applications isn’t easy. Anything served over HTTP can be considered a web app. Shiny apps and Plumber APIs are both, technically, web frameworks—which we’ll refer to generally as “apps.”

Each framework requires, at minimum, two things:

  1. The host to serve the app on (e.g. 127.0.0.1)
  2. The port for the app to listen on e.g. the 8080 in http://127.0.0.1:8080.

Frameworks often provide different customizations and bespoke ways to start them.

The _server.yml standard, introduced by the {plumber2} R package, defines a standard interface to start apps which will simplify app deployment for R developers.

The standard

Each R package has its own way to start an app:

Each of these provides, at minimum, a way to set the host and the port , as well as additional configuration options.

Instead, the _server.yml standard enforces that every app can be started the same way:

R
engine:::launch_server(
    "_server.yml",
    host = "127.0.0.1",
    port = 8080L
)

Each engine must have a function (it doesn’t need to be exported hence the :::) called launch_server() with 3 arguments:

  • the path to a _server.yml
  • the host to serve the app on
  • the port on the host to use

The engine is the R package that is serving the app which is responsible for defining and reading its own _server.yml file for configuration.

File structure

The standard leaves a lot of room for what actually goes into the _server.yml file. However, at minimum, it requires one top level field:

yaml
engine: pkgname

The launch_server() function is actually responsible for capturing the configuration in the yaml file and making its own decisions. In the case of {plumber2} this includes fields routes, constructor, and options.

Support in ricochet

As of ricochet v0.20, the _server.yml standard is supported. As a result, ricochet supports any R package that implements the standard. Today, that includes:

To illustrate the _server.yml capabilities, we deployed a website built on tailwindcss and {plumber2} (source).

penguins-pages

Run the app locally

bash
git clone --filter=blob:none --sparse https://github.com/ricochet-rs/test-apps.git test-apps
git -C test-apps sparse-checkout set r/plumber2-tailwind-ssr
cd test-apps/r/plumber2-tailwind-ssr

Deploy the app

To deploy this app ensure the latest version of the ricochet cli is installed and logged into the try.ricochet.rs instance.

bash
curl -fsSL https://raw.githubusercontent.com/ricochet-rs/cli/main/install.sh | sh
ricochet server add try https://try.ricochet.rs
ricochet login -S try
ricochet deploy -S try