The idea is to show how to use webR with a more complex example (more then the hello world with a build in HTTP server) using R dependencies containing Fortran code (so the worst case possible :D). The endpoint minpack is based on Nonlinear Least-Squares Data Fitting - Example D.2 .
You will need to either install bun or use a docker image mounting the src folder into the image. I will use docker since it is easier for me to work with.
Get the image that you like the most. Example
docker pull oven/bun:1.3.10-debian
Run the image mounting the src folder into the container
docker container run --rm -it -p 3000:3000 -v ./src:/home/bun/app oven/bun:1.3.10-debian bash
Install the dev containers extension in vs code. Once you open this project vs code will prompt you to open the project in the bun:1.3.10-debian container.
Initialize bun project
bun init
leading to the setup
package name (app): webrbun
entry point (index.ts):
Done! A package.json file was saved in the current directory.
+ index.ts
+ .gitignore
+ tsconfig.json (for editor auto-complete)
+ README.md
To get started, run:
bun run index.ts
Add the dependencies
bun add elysia @elysiajs/swagger webr
add dev dependencies for linting and formatting
bun add --dev --exact @biomejs/biome
bunx biome init
Check everything is working
bun run ./index.ts
output
Hello via Bun!
Add script(s) to the package.json file for easier calling of repeated steps
"scripts": {
"runREST": "bun run ./index.ts"
}
I will build a REST api using
- ElysiaJS - backend/routing etc.
- @elysiajs/swagger - plugin to auto-generate openapi page
- @elysiajs/static - plugin to serve static content
- WebR - model fitting and random number generation
- biomejs - lint and format
- vanjs - minimal reactive frontend library
Running
bun runREST
will make the REST API and WEB UI available under localhost:3001.
You can test the endpoints with the default values using the openapi endpoint localhost:3001/swagger.
Microsoft. (2025). Copilot (GPT-4) [Large Language Model]. Retrieved from https://copilot.microsoft.com