From 623ff976d096990a58361eb86856201eb83b5db6 Mon Sep 17 00:00:00 2001 From: Jon Mease Date: Wed, 13 Dec 2023 19:17:26 -0500 Subject: [PATCH 1/7] Add "jupyter" renderer based on JupyterChart --- altair/vegalite/v5/display.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/altair/vegalite/v5/display.py b/altair/vegalite/v5/display.py index 93926e62b..7b23e0710 100644 --- a/altair/vegalite/v5/display.py +++ b/altair/vegalite/v5/display.py @@ -86,6 +86,13 @@ def svg_renderer(spec: dict, **metadata) -> Dict[str, str]: ) +def render_jupyter(spec): + """Render chart using the JupyterChart Jupyter Widget""" + from altair import Chart, JupyterChart + + return JupyterChart(chart=Chart.from_dict(spec))._repr_mimebundle_() + + html_renderer = HTMLRenderer( mode="vega-lite", template="universal", @@ -105,6 +112,7 @@ def svg_renderer(spec: dict, **metadata) -> Dict[str, str]: renderers.register("json", json_renderer) renderers.register("png", png_renderer) renderers.register("svg", svg_renderer) +renderers.register("jupyter", render_jupyter) renderers.enable("default") From d21716616dbebce24c02d26f8940153a6347296e Mon Sep 17 00:00:00 2001 From: Jon Mease Date: Wed, 13 Dec 2023 19:25:01 -0500 Subject: [PATCH 2/7] Add release note --- doc/releases/changes.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/releases/changes.rst b/doc/releases/changes.rst index 206e7f8c3..6cb89fee2 100644 --- a/doc/releases/changes.rst +++ b/doc/releases/changes.rst @@ -8,6 +8,8 @@ Version 5.3.0 (unreleased month day, year) Enhancements ~~~~~~~~~~~~ +- Add "jupyter" renderer which uses JupyterChart for rendering (#3283) + Bug Fixes ~~~~~~~~~ Backward-Incompatible Changes From c90d3236f8a302159235a8ebe55cdcda755f1f4b Mon Sep 17 00:00:00 2001 From: Jon Mease Date: Thu, 14 Dec 2023 13:42:58 -0500 Subject: [PATCH 3/7] rename to jupyter_renderer --- altair/vegalite/v5/display.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/altair/vegalite/v5/display.py b/altair/vegalite/v5/display.py index 7b23e0710..da7db78e5 100644 --- a/altair/vegalite/v5/display.py +++ b/altair/vegalite/v5/display.py @@ -86,7 +86,7 @@ def svg_renderer(spec: dict, **metadata) -> Dict[str, str]: ) -def render_jupyter(spec): +def jupyter_renderer(spec: dict): """Render chart using the JupyterChart Jupyter Widget""" from altair import Chart, JupyterChart @@ -112,7 +112,7 @@ def render_jupyter(spec): renderers.register("json", json_renderer) renderers.register("png", png_renderer) renderers.register("svg", svg_renderer) -renderers.register("jupyter", render_jupyter) +renderers.register("jupyter", jupyter_renderer) renderers.enable("default") From 86309ac274832b3af9da42b11f41e696acf339a8 Mon Sep 17 00:00:00 2001 From: Jon Mease Date: Thu, 14 Dec 2023 14:07:05 -0500 Subject: [PATCH 4/7] # type: ignore[attr-defined] --- altair/vegalite/v5/display.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/altair/vegalite/v5/display.py b/altair/vegalite/v5/display.py index da7db78e5..b13d62e06 100644 --- a/altair/vegalite/v5/display.py +++ b/altair/vegalite/v5/display.py @@ -90,7 +90,9 @@ def jupyter_renderer(spec: dict): """Render chart using the JupyterChart Jupyter Widget""" from altair import Chart, JupyterChart - return JupyterChart(chart=Chart.from_dict(spec))._repr_mimebundle_() + # Need to ignore attr-defined mypy rule because mypy doesn't see _repr_mimebundle_ + # conditionally defined in AnyWidget + return JupyterChart(chart=Chart.from_dict(spec))._repr_mimebundle_() # type: ignore[attr-defined] html_renderer = HTMLRenderer( From cb24bd3ef13a59dc584ceeceed3b7d08b81d21c0 Mon Sep 17 00:00:00 2001 From: Jon Mease Date: Sat, 16 Dec 2023 08:30:21 -0500 Subject: [PATCH 5/7] Add jupyter renderer doc section --- doc/user_guide/display_frontends.rst | 6 ++++++ doc/user_guide/jupyter_chart.rst | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/doc/user_guide/display_frontends.rst b/doc/user_guide/display_frontends.rst index ad418bea8..573962e62 100644 --- a/doc/user_guide/display_frontends.rst +++ b/doc/user_guide/display_frontends.rst @@ -40,6 +40,12 @@ The most used built-in renderers are: newer versions of JupyterLab_, nteract_, and `VSCode-Python`_, but does not work with the `Jupyter Notebook`_, or with tools like nbviewer_ and nbconvert_. +``alt.renderers.enable("jupyter")`` + *(added in version 5.3.0):* Output the chart using :ref:`user-guide-jupyterchart`. This renderer + is compatible with environments that support third-party Jupyter Widgets including + JupyterLab_, `Jupyter Notebook`_, `VSCode-Python`_, and `Colab`_. + It requires a web connection in order to load relevant Javascript libraries. + In addition, Altair includes the following renderers: - ``"default"``, ``"colab"``, ``"kaggle"``, ``"zeppelin"``: identical to ``"html"`` diff --git a/doc/user_guide/jupyter_chart.rst b/doc/user_guide/jupyter_chart.rst index 92ac6944c..d2bcaa63a 100644 --- a/doc/user_guide/jupyter_chart.rst +++ b/doc/user_guide/jupyter_chart.rst @@ -1,7 +1,7 @@ .. _user-guide-jupyterchart: -JupyterChart Interactivity -========================== +JupyterChart +============ The ``JupyterChart`` class, introduced in Vega-Altair 5.1, makes it possible to update charts after they have been displayed and access the state of :ref:`user-guide-interactions` from Python. From 30f97566043bbad61142a01e2fb54599d8546463 Mon Sep 17 00:00:00 2001 From: Jon Mease Date: Tue, 19 Dec 2023 09:45:34 -0500 Subject: [PATCH 6/7] Update docs to be clear that you can't access params with jupyter renderer --- doc/user_guide/display_frontends.rst | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/doc/user_guide/display_frontends.rst b/doc/user_guide/display_frontends.rst index 573962e62..10ea5fd79 100644 --- a/doc/user_guide/display_frontends.rst +++ b/doc/user_guide/display_frontends.rst @@ -41,10 +41,14 @@ The most used built-in renderers are: with the `Jupyter Notebook`_, or with tools like nbviewer_ and nbconvert_. ``alt.renderers.enable("jupyter")`` - *(added in version 5.3.0):* Output the chart using :ref:`user-guide-jupyterchart`. This renderer + *(added in version 5.3):* Output the chart using :ref:`user-guide-jupyterchart`. This renderer is compatible with environments that support third-party Jupyter Widgets including JupyterLab_, `Jupyter Notebook`_, `VSCode-Python`_, and `Colab`_. - It requires a web connection in order to load relevant Javascript libraries. + It requires a web connection in order to load relevant Javascript libraries. Note that, + although this renderer uses ``JupyterChart``, it does not provide the + ability to access value and selection params in Python. To do so, create a ``JupyterChart`` + object explicitly following the instructions in the :ref:`user-guide-jupyterchart` + documentation. In addition, Altair includes the following renderers: From 7bb0f850df7d322a50bfb000fad7b19ccb796eb8 Mon Sep 17 00:00:00 2001 From: Jon Mease Date: Fri, 22 Dec 2023 05:36:51 -0500 Subject: [PATCH 7/7] Update doc/releases/changes.rst Co-authored-by: Stefan Binder --- doc/releases/changes.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/releases/changes.rst b/doc/releases/changes.rst index 6cb89fee2..aecddfe6c 100644 --- a/doc/releases/changes.rst +++ b/doc/releases/changes.rst @@ -8,7 +8,7 @@ Version 5.3.0 (unreleased month day, year) Enhancements ~~~~~~~~~~~~ -- Add "jupyter" renderer which uses JupyterChart for rendering (#3283) +- Add "jupyter" renderer which uses JupyterChart for rendering (#3283). See :ref:`renderers` for more information. Bug Fixes ~~~~~~~~~