R
This page covers the requirements and internals of deploying R content to ricochet.
Project requirements
Section titled “Project requirements”Every R deployment requires a renv.lock file in the project root.
This lockfile is generated by {renv} and records all package dependencies and their versions.
Example _ricochet.toml
Section titled “Example _ricochet.toml”[content]name = "My Shiny App"entrypoint = "app.R"access_type = "external"content_type = "shiny"
[language]name = "r"packages = "renv.lock"
[serve]min_instances = 0max_instances = 5Supported content types
Section titled “Supported content types”R content items can be deployed as apps or tasks.
Content Type | Description |
|---|---|
plumber | An API developed using {plumber}. |
ambiorix | An API or web app developed using {ambiorix}. |
shiny | A web app developed using {shiny}. |
rmd-shiny | An R Markdown document using a Shiny runtime. |
quarto-r-shiny | A Quarto document using a Shiny runtime. |
serverless-r | R functions deployed as an API. |
r-service | A generic web app or API using an R runtime. |
Content Type | Description |
|---|---|
r | An R script with the extension .R or .r. |
rmd | An R Markdown document. Can be served as a static site. |
quarto-r | A Quarto document using an R runtime. Can be served as a static site. |
How ricochet runs R content
Section titled “How ricochet runs R content”R version discovery
Section titled “R version discovery”Ricochet discovers R installations on the host machine.
We recommend installing R versions via rig for the best experience managing multiple versions:
rig add <version>You can also install R from CRAN or your distribution’s package manager.
Environment restoration
Section titled “Environment restoration”Ricochet vendors renv at $RICOCHET_HOME/vendor.
When a bundle is deployed, ricochet restores R package dependencies from the renv.lock file using the vendored renv.
Using the API
Section titled “Using the API”You can deploy and manage R content programmatically using the ricochet REST API.
The examples below use {httr2}.
API keys are created in the ricochet UI under Credentials → API Keys.
Deploy a bundle
Section titled “Deploy a bundle”Bundle your project as a .tar.gz archive and upload it with the _ricochet.toml config.
library(httr2)
server <- "https://try.ricochet.rs"api_key <- Sys.getenv("RICOCHET_API_KEY")
# Create a tar.gz bundle of the project directorybundle_path <- tempfile(fileext = ".tar.gz")tar(bundle_path, files = ".", compression = "gzip")
# Deploy new contentresp <- request(server) |> req_url_path_append("api", "v0", "content", "upload") |> req_headers(Authorization = paste("Key", api_key)) |> req_body_multipart( bundle = curl::form_file(bundle_path, type = "application/gzip"), config = curl::form_file("_ricochet.toml", type = "application/toml") ) |> req_perform()
result <- resp_body_json(resp)result$id#> "01JSZAXZ3TSTAYXP56ARDVFJCJ"To redeploy existing content, pass id instead of config:
resp <- request(server) |> req_url_path_append("api", "v0", "content", "upload") |> req_headers(Authorization = paste("Key", api_key)) |> req_body_multipart( bundle = curl::form_file(bundle_path, type = "application/gzip"), id = "01JSZAXZ3TSTAYXP56ARDVFJCJ" ) |> req_perform()Invoke a task
Section titled “Invoke a task”content_id <- "01JSZAXZ3TSTAYXP56ARDVFJCJ"
resp <- request(server) |> req_url_path_append("api", "v0", "content", content_id, "invoke") |> req_headers(Authorization = paste("Key", api_key)) |> req_body_json(list(params = list(n = 100))) |> req_perform()
resp_body_json(resp)List your content
Section titled “List your content”resp <- request(server) |> req_url_path_append("api", "v0", "user", "items") |> req_headers(Authorization = paste("Key", api_key)) |> req_perform()
items <- resp_body_json(resp)