Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "jupyter" renderer based on JupyterChart #3283

Merged
merged 8 commits into from
Dec 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions altair/vegalite/v5/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,15 @@ def svg_renderer(spec: dict, **metadata) -> Dict[str, str]:
)


def jupyter_renderer(spec: dict):
"""Render chart using the JupyterChart Jupyter Widget"""
from altair import Chart, JupyterChart

# 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(
mode="vega-lite",
template="universal",
Expand All @@ -105,6 +114,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", jupyter_renderer)
renderers.enable("default")


Expand Down
1 change: 1 addition & 0 deletions doc/releases/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Version 5.3.0 (unreleased month day, year)

Enhancements
~~~~~~~~~~~~
- Add "jupyter" renderer which uses JupyterChart for rendering (#3283). See :ref:`renderers` for more information.
- Support restrictive FIPS-compliant environment (#3291)

Bug Fixes
Expand Down
10 changes: 10 additions & 0 deletions doc/user_guide/display_frontends.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ 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):* 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. 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:

- ``"default"``, ``"colab"``, ``"kaggle"``, ``"zeppelin"``: identical to ``"html"``
Expand Down
4 changes: 2 additions & 2 deletions doc/user_guide/jupyter_chart.rst
Original file line number Diff line number Diff line change
@@ -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.

Expand Down