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 JupyterChart section to Users Guide #3137

Merged
merged 9 commits into from
Aug 10, 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
29 changes: 17 additions & 12 deletions altair/jupyter/jupyter_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ def _on_change_chart(self, change):

if params is not alt.Undefined:
for param in new_chart.params:
if isinstance(param.name, alt.ParameterName):
clean_name = param.name.to_json().strip('"')
else:
clean_name = param.name

select = getattr(param, "select", alt.Undefined)

if select != alt.Undefined:
Expand All @@ -158,27 +163,27 @@ def _on_change_chart(self, change):
):
# Point selection with no associated fields or encodings specified.
# This is an index-based selection
selection_types[param.name] = "index"
empty_selections[param.name] = IndexSelection(
name=param.name, value=[], store=[]
selection_types[clean_name] = "index"
empty_selections[clean_name] = IndexSelection(
name=clean_name, value=[], store=[]
)
else:
selection_types[param.name] = "point"
empty_selections[param.name] = PointSelection(
name=param.name, value=[], store=[]
selection_types[clean_name] = "point"
empty_selections[clean_name] = PointSelection(
name=clean_name, value=[], store=[]
)
elif select_type == "interval":
selection_types[param.name] = "interval"
empty_selections[param.name] = IntervalSelection(
name=param.name, value={}, store=[]
selection_types[clean_name] = "interval"
empty_selections[clean_name] = IntervalSelection(
name=clean_name, value={}, store=[]
)
else:
raise ValueError(f"Unexpected selection type {select.type}")
selection_watches.append(param.name)
initial_vl_selections[param.name] = {"value": None, "store": []}
selection_watches.append(clean_name)
initial_vl_selections[clean_name] = {"value": None, "store": []}
else:
clean_value = param.value if param.value != alt.Undefined else None
initial_params[param.name] = clean_value
initial_params[clean_name] = clean_value

# Setup params
self.params = Params(initial_params)
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions doc/_static/jupyter_chart/simple_bar.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/_static/jupyter_chart/updating_charts.mov
Binary file not shown.
1 change: 1 addition & 0 deletions doc/user_guide/data.rst
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,7 @@ data before usage in Altair using GeoPandas for example as such:
customization
configuration
saving_charts
jupyter_chart
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this section should be just under the section "Interactive Charts". It is definitely the closest to that section thematically even if it is not as central to Altair as some of the other section. I also wonder if we should call this section `JupyterChart Interactivity" or something similar to more clearly signal what it is about.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed to "JupyterChart Interactivity" in 5723c28



.. toctree::
Expand Down
16 changes: 8 additions & 8 deletions doc/user_guide/interactions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -991,11 +991,11 @@ For more information on how to fine-tune selections, including specifying other
mouse and keystroke options, see the `Vega-Lite Selection documentation
<https://vega.github.io/vega-lite/docs/selection.html>`_.

Limitations
~~~~~~~~~~~

Some possible use cases for the above interactivity are not currently supported by Vega-Lite, and hence are not currently supported by Altair. Here are some examples.

1. If we are using a ``selection_point``, it would be natural to want to return information about the chosen data point, and then process that information using Python. This is not currently possible, so any data processing will have to be handled using tools such as ``transform_calculate``, etc. You can follow the progress on this in the following issue: https://github.com/altair-viz/altair/issues/1153.

- The dashboarding package ``Panel`` has added support for processing Altair selections with custom callbacks in their 0.13 release. This is currently the only Python dashboarding package that supports custom callbacks for Altair selections and you can read more about how to use this functionality in `the Panel documentation <https://pyviz-dev.github.io/panel/reference/panes/Vega.html#selections>`_.
Access Params From Python
~~~~~~~~~~~~~~~~~~~~~~~~~
As of Vega-Altair 5.1, it's now possible to access the values of variable and selection parameters
from Python using the :ref:`user-guide-jupyterchart` class.

Additionally, the dashboarding package ``Panel`` includes support for processing Altair selections
with custom callbacks. See the
`Panel documentation <https://panel.holoviz.org/reference/panes/Vega.html#selections>`_.
Loading