Case study
Live Data Visualisation with R on the JVM
A Spring Boot service that reads one MongoDB record per second and has R — running inside the same JVM on GraalVM — draw a live chart of the last 100 values.
The problem
Java had the web server and the database driver; R had the plotting. The task was to use both in one process, instead of running a separate R server and passing data between two programs.
What I did & decided
DataServicereads one row from MongoDB per request (Row-1…Row-100).PlotControllerpasses the value to an R function (plot.R) through GraalVM's polyglot support and returns the SVG it draws, with aRefresh: 1header so the browser asks again every second.plot.Rkeeps the last 100 values and draws them with latticexyplot().- An R context runs one thread at a time, so calls into it are synchronised; the Spring controller can still serve many requests.
What came of it
- One process, one start command (
mvn spring-boot:run), and a chart that updates once a second. - The README explains how to import the data into MongoDB and run it from scratch.
Next case: Task Management API