A sample project to setup Pyodide with built in packages and a Web Worker, visible at https://pyo-nightshade.vercel.app/.
Below is a brief explaination of the code breakdown.
A modified Cartopy Nightshade sample.
If running in Pyodide:
- the drawing is exported to a base 64 string to be loaded as an image in the main thread of the browser
- the
AGG
Matplotlib backend is used when running in a Web Worker (see the open issue as of the creation of this project)
If running in a regular Python environment, the drawing is displayed using the default Matplotlib backend.
- Import Pyodide
- Initialize Pyodide
- Load packages
- Import the Python code as a module
- Render images at intervals
Provide a placeholder to display the data coming from the Worker event.
From a shell:
# Create a Python virtual environment
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.dev.txt
python plot.py
The javascript and html code can be tested after running python3 -m http.server
and visiting http://localhost:8000
.