R on Miren
R isn't auto-detected, so you deploy it with a Dockerfile.miren. This guide uses
Plumber to turn R functions into an HTTP API — a common way
to serve models and data-science code.
Ask your AI coding agent to "set up this R API on Miren" after installing the
Miren agent skills. It adds the Dockerfile.miren, binds Plumber to
0.0.0.0:$PORT, and deploys — using this page as its reference.
Do you need a Dockerfile?
Yes. Miren doesn't auto-detect R, so add a Dockerfile.miren to your project root.
Miren builds from it instead of guessing the stack — see
Using Dockerfile.miren.
Miren auto-detects and builds common stacks (Python, Node, Bun, Go, Ruby, Rust) without a Dockerfile. This language isn't one of them yet — if you'd like first-class support, request it.
Bind to the injected port
Miren injects PORT and routes traffic to it. Define endpoints in a Plumber file and
run it on 0.0.0.0 at the injected port.
plumber.R:
#* @get /
#* @serializer text
function() {
"Hello from R on Miren!\n"
}
entrypoint.R:
library(plumber)
port <- as.integer(Sys.getenv("PORT", "8080"))
pr("plumber.R") |> pr_run(host = "0.0.0.0", port = port)
The Dockerfile
Create Dockerfile.miren in your project root. The rstudio/plumber image already has
R and Plumber installed:
FROM rstudio/plumber:latest
WORKDIR /app
COPY . /app
EXPOSE 8080
If you need extra packages, install them in the build:
RUN R -e 'install.packages(c("DBI", "RPostgres"))'.
.dockerignore
.git
Set up the app
Even with a Dockerfile.miren, Miren needs at least one service defined — it
doesn't use the image's CMD as the start command. Add a Procfile:
web: Rscript /app/entrypoint.R
Then create .miren/app.toml naming your app and deploy from your project root:
name = "r-bench"
miren deploy
If no service is defined, the build succeeds but the deploy stops with
no services defined: please define at least one service in a Procfile or .miren/app.toml.
Environment variables
Set variables with miren env set — -e for plain values, -s for secrets (masked in
output and logs). Read them with Sys.getenv("KEY"):
miren env set -e LOG_LEVEL=info
miren env set -s DATABASE_URL
You can also declare variables in .miren/app.toml:
[[env]]
key = "DATABASE_URL"
value = ""
required = true
sensitive = true
See App Configuration — Environment Variables.
Agent quick reference
- Detection: none — requires
Dockerfile.miren - Base image:
rstudio/plumber:latest(R + Plumber preinstalled) - Service is required: define a
Procfile(web: Rscript /app/entrypoint.R) — the imageCMDis not used - Port:
Sys.getenv("PORT");pr_run(host = "0.0.0.0", port = port) - Env vars:
miren env set -e/-s; read withSys.getenv
Next steps
- Using Dockerfile.miren — how custom builds work
- App Configuration — customize
.miren/app.toml - Deployment — how deploys build and activate