{ZB}Ziyad Alboghdady

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.

StackSpring Boot · Java 17 · MongoDB · R (lattice) · GraalVM FastR
RoleGroup project (SWE 307 Big Data)
WhenOct 2026
SourceGitHub repository

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

  • DataService reads one row from MongoDB per request (Row-1 … Row-100).
  • PlotController passes the value to an R function (plot.R) through GraalVM's polyglot support and returns the SVG it draws, with a Refresh: 1 header so the browser asks again every second.
  • plot.R keeps the last 100 values and draws them with lattice xyplot().
  • 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