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:
- The
hostto serve the app on (e.g.127.0.0.1) - The
portfor the app to listen on e.g. the8080inhttp://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:
shiny::runApp()plumber::pr_run(),plumber::plumb("api.R")$run()plumber2::api_run()Ambiorix$run()nanonext::http_server()
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:
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
hostto serve the app on - the
porton 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:
engine: pkgnameThe 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).
Run the app locally
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-ssrDeploy the app
To deploy this app ensure the latest version of the ricochet cli is installed and logged into the try.ricochet.rs instance.
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