AI to make interactive figures

Stats and Maths Teaching Innovations Meetup

Tom Coleman

2026-12-04

Context

  • Lecturer (Education Focused) in pure mathematics

  • passion for creating good resources / very shallow technical background

  • currently using Quarto to produce publicly available free-to-use, accessible and inclusive maths and stats support resources (at https://starmast.org)

  • co-create these resources with students as part of a Vertically Integrated Project

What I want

interactive figures / elements that enhance learning of difficult mathematics and statistical topics, but also

  • consistency in visual design across the website

  • any interactive elements to be digitally accessible

  • language used to reflect the tone of the resources

  • not to introduce concepts beyond the guide in question

Methods (1/2)

wide range of topics - wide range of methods for best results?

  • R package webexercises for ‘quick-check’ questions (T/F, multiple choice…)

  • Quarto’s synergy with R encourages R Shiny apps, particularly good for statistics

    • works best with a dedicated R Shiny server (money)

    • but can use R Shinylive to run these apps without a server (free, at the cost of longer loading times - more on this later)

  • Desmos is best for graphs / recognisable brand for students / accessibility features built-in

    • can use Desmos API environment for full editability (money)

    • can embed directly from Desmos without API (free, restricted features)

  • raw html/integrated JavaScript provides natural flexibility for everything else (calculators, animations…)

Methods (2/2)

generative AI provides starting points for use of these tools

  • R Shiny Assistant (for R Shiny Live, more on that later)

  • Copilot (for html/javascript)

  • ChatGPT (for html/Desmos API environment)

[other agentic AI tools/large language models/harbingers of human armaggeddon are available]

Prior to the incident

  • very disjointed production of interactive elements, with duplication of work across many sessions

  • mostly R Shinylive, with some Copilot/ChatGPT

  • range of different inputs led to range of different visual styles

The incident

I used to use R Shiny to create all my statistics figures, which relied on an external server (shinylive, via WebAssembly and WebR) that served the Shiny application.

This was acheivable by R Shiny Assistant.

While very flexible in what it can do, these applications were always plagued with long loading times, and since it was an external server, was at the mercy of their updates and dependencies.

The clean-up

ported all my shinylive apps involving ggplot (the offending package) to html/javascript - got rid of the long loading times and created a cleaner-looking application

R Shiny figure from Factsheet: Normal distribution, written by a first-year student. It is a picture of an interactive normal distribution figure, with sliders to modify the mean and the standard deviation.

R Shiny figure from Factsheet: Normal distribution, written by a first-year student

html figure from Factsheet: Normal distribution, written by a first-year student. It is a picture of an interactive normal distribution figure, with sliders to modify the mean and the standard deviation.

html figure from Factsheet: Normal distribution, written by a first-year student

The upside

  • the sudden need to replace 80% of our interactive figures overnight meant that a pipeline needed to be developed

  • an important part of the website is the visual consistency throughout, and so a template was crucial

  • this experience made me think more deeply about how to get the best out of AI to mass produce interactive elements

Example

Chat log for the eigenbingo tool

Final output

Some tips for prompting

  • be specific up front to get something close to what you want to - even down to hex codes for colours!

  • AI does not take digital accessibility concerns into account, you will have to ask for it

  • don’t be afraid to tell AI to get back in its lane if it doesn’t serve your purpose

  • if you are not comfortable with editing chunks of code it gives, ask it to regenerate the entire file

  • be mindful of the context in which you place your apps (‘name spacing’)

  • once you’re happy with the templating and the results you are generating, use the same chat to generate further figures

Showcase

Stats

Not stats

What’s next?

my experiences allow me to teach students on my VIP to use generative AI responsibly and how to match an existing brief (employability points for me!)

  • students currently working on interactive elements for matrix multiplication, matrices as linear maps, eigenvalues and eigenvectors, row operation calculator, grad-div-curl visualiser and calculator, Lagrange multipliers (and they look stunning!)

Want more?

thank you for listening!

Appendix: how to embed (1/2)

use conditional content tags if using multiple outputs

::: {.content-visible when-format="html"}
interactive content
:::

::: {.content-hidden when-format="html"}
non-interactive content for printable versions
:::

Appendix: how to embed (2/2)

(three ticks){=html}
embeddable content
(three ticks)

with API key

format:
  html:
    include-in-header: 
    - text: <script src="desmos_API_key_link"></script>

then use Desmos’ documentation to start building (clickable) (step 1 covered by above)

without API key

  • draw graph using Desmos graphical calculator
  • share button / ‘embed snapshot’
  • paste iframe code into html tags in Quarto
(three ticks){=html}
Desmos iframe
(three ticks)

for Shinylive, no server

  • install shinylive quarto extension link to github

  • in _quarto.yml file (or put filter on each relevant .qmd file)

format:
  html:
    include-in-header: 
    - text: <script src="https://esm.sh/shinylive-r"></script>
    filters:
    - shinylive
  • in .qmd file
[three ticks]{shinylive-r}
#| standalone: true
#| viewerHeight: 500

R Shiny app here
[three ticks]
[three ticks]{r, setup, include = FALSE}
library("webexercises")
[three ticks]
  • follow documentation to create webex-boxes where you want questions in your text