Sphinx-anywidget#9
Open
CSSFrancis wants to merge 7 commits intomainfrom
Open
Conversation
Adds anyplotlib/sphinx_anywidget/ — a self-contained Sphinx extension that
makes any anywidget.AnyWidget-based figure interactive in documentation
pages via Pyodide, with no server or Jupyter kernel required.
Key changes
-----------
anyplotlib/sphinx_anywidget/
__init__.py Sphinx extension entry point; auto-injects JS/CSS,
builds wheel at docs-build time, registers directive
_scraper.py Generic AnywidgetScraper (replaces ViewerScraper);
detects '# Interactive' comment tag to opt-in per block
_repr_utils.py Self-contained HTML builder (no anyplotlib dep);
uses awi_state/awi_event message protAdds anyplotlib/sphinx_anywidget/ — a self-contained Sphinx extension that
makes any anywidget.AnyWidget-based figure interactive in documentation
pages via Pyodide, with no server or Jupyter kernel required.
Key changes
-----------
anyplotlib/sphinx_anywidget/
__init__.py Sphinx extension entry point;?akes any anywidget.AnyWidget-based figure inywidget monkey-patch replaces thpages via Pyodide, with no server or Jupyter kernel required.
Key chanecKey changes
-----------
anyplotlib/sphinx_anywidget/
_ ----------inanyplotlibivate-btn, awi-static-icon)
any builds wheel at docs-build time, registers directf- _scraper.py Generic Anywie_fig_id attribute
- _push() / _push_layout() / _push_widget() always write to traitlets;
the generic monkey- _repr_utils.py Sethe change via
traitlets.observe(names=All) — no uses awi_state/awi_event message protAdds anyplstmakes any anywidget.AnyWidget-based figure interactive in documentation
pages via Pyodide, with no server or Jupyter kernel required.
Keespages via Pyodide, with no server or Jupyter kernel required.
Key channsKey changes
-----------
anyplotlib/sphinx_anywidget/
__ini_g----------f
anyplotlibtm __init__.py SphitKey chanecKey changes
-----------
anyplotlib/sphinx_anywidget/
_ ----------inanyplotlibivate-btn, awi-static-icon)
any builds wheel at docs-build time, registers to-------raits directly
anyplotlib b _ ----------inanyplogeany builds wheel at docs-build timta - _push() / _push_layout() / _push_widget() always write to traitlets;
the generic monkey- _repr_utils.py ton
- Update mock r the generic monkey- _repr_(_patched_init pattern)
Usage in other pro traitlets.observe(names=All) — no nxpages via Pyodide, with no server or Jupyter kernel required.
Keespages via Pyodide, with no server or Jupyter kernel required.
Key channsKey changes
-----------
anyplotlib/sphinxteracKeespages via Pyodide, with no server or Jupyter kerngit log --oneline -3
…teractive figures
…bridge.js for anyplotlib extension
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #9 +/- ##
===========================================
- Coverage 87.79% 74.44% -13.36%
===========================================
Files 7 12 +5
Lines 1901 2250 +349
===========================================
+ Hits 1669 1675 +6
- Misses 232 575 +343 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Owner
Author
|
Long time coming.... But live responsive interactive documentation should be possible with this... I need to set up github to host docs from PRs still but once that is up it should be really nice for demoing a feature, writing documentation etc. Screen.Recording.2026-05-03.at.2.30.58.PM.mov |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces several enhancements and new features focused on improving interactive documentation support, widget communication, and robustness of the plotting library. The most significant addition is the new
sphinx_anywidgetSphinx extension, which enables fully interactive figures in documentation using Pyodide, without requiring a server or Jupyter kernel. Additionally, the PR improves the widget–parent page communication bridge, makes colormap handling more robust, and ensures deterministic panel IDs for subplot panels. Minor changes include code comments for Sphinx Gallery compatibility and a new end-to-end test for the Playwright-based thumbnail scraper.Sphinx extension for interactive documentation:
anyplotlib.sphinx_anywidgetSphinx extension, which enables interactive anywidget-based figures in documentation via Pyodide, provides a custom RST directive (.. anywidget-figure::), and integrates with Sphinx Gallery. This includes automatic wheel building for the target package and seamless asset injection. [1] [2]Widget–parent page communication improvements:
_repr_utils.pyto support robust two-way communication between widgets and the parent page usingpostMessage, including loop-prevention flags, event forwarding, and handling inbound state updates for Pyodide-based interactivity. [1] [2] [3] [4] [5]Plotting library robustness and determinism:
figure_plots.pyto prefercolorcetbut gracefully fall back tomatplotlibor a gray ramp if unavailable, making color mapping more robust across environments.Testing and Sphinx Gallery compatibility:
_test_scraper.py.# Interactivecomments to several example scripts for Sphinx Gallery compatibility. [1] [2] [3] [4] [5]Event dispatching improvements:
figure.pyto centralize event dispatch logic, allowing both traitlet observers and the Pyodide bridge to process interaction events consistently.