Plotly figures with Pyodide and standalone client-side Python script

I’d like to run a simple Python script that generates Plotly figures with interactive JavaScript in the client-side Python programming using Pyodide.

  • I can already accomplish this within JupyterLite notebook

  • The Python script pulls data using fetch and then performs calculations using pandas

  • However, I’d like to have this standalone: run some dynamic Python code embedded in an HTML page and then show the data using Plotly. Preferably interactive chart, but a static image can do as well.

  • Happy to build Pyodide offline beforehand, all libraries, bells and whistles included

I know how to run Python using Pyodide, but I am unsure how to integrate with Plotly and how to pass data from Pyodide’s background worker context to Plotly to be consumed in the frontend JavaScript? What’s the recommended integration approach for standalone client-side Python with Pyodide and Plotly figures? Are there documentation or examples on such?

This question is also available on StackOverflow for reputation hunters.