marimo-team / marimo

A reactive notebook for Python β€” run reproducible experiments, execute as a script, deploy as an app, and version with git.
https://marimo.io
Apache License 2.0
7.95k stars 278 forks source link

mpl proxy for matplotlib process #2882

Closed maxtheman closed 3 days ago

maxtheman commented 5 days ago

πŸ“ Summary

This represents the matplotlib fix to create a proxy middleware which connects the main starlette process to the mpl starlette process.

Using this mapplotlib can be used in production on Docker for any kind of interactive stuff.

See my demo app here, which is finally working: https://causal-quartets.fly.dev/

I left the environmental variables in the codebase so that you could customize the port or hosts for some reason in the future, but I removed references to them from the documentation since I think that would be more of a developer-facing thing anyway.

πŸ” Description of Changes

  1. Creates AsyncHTTPClient class to manage HTTP responses between the two starlette processes without any dependencies (i.e., no httpx)
  2. Fixes The WebSocket handling from the original implementation of the proxy class. There were two things wrong: The websocket proxy was dropping the figure url params required for matplotlib to find the figure. There was also a bare Exception that was silently catching the assertion failure in _mpl, which made diagnosis difficult.
  3. adds 9 tests which successfully simulate and range the gamut across all of the issues we were seeing and make sure that all of the HTTP and WebSocket methods we're talking about work correctly as well as testing it directly with the mpl middleware.

πŸ“‹ Checklist

πŸ“œ Reviewers

@mscolnick - finally ready for you

vercel[bot] commented 5 days ago

The latest updates on your projects. Learn more about Vercel for Git β†—οΈŽ

Name Status Preview Comments Updated (UTC)
marimo-docs βœ… Ready (Inspect) Visit Preview πŸ’¬ Add feedback Nov 18, 2024 10:25pm
marimo-storybook βœ… Ready (Inspect) Visit Preview πŸ’¬ Add feedback Nov 18, 2024 10:25pm
github-actions[bot] commented 5 days ago

All contributors have signed the CLA ✍️ βœ…
Posted by the CLA Assistant Lite bot.

maxtheman commented 3 days ago

I have read the CLA Document and I hereby sign the CLA