Skip to content

Commit

Permalink
Add example of how to update title based on a selection parameter (#3353
Browse files Browse the repository at this point in the history
)
  • Loading branch information
joelostblom authored Mar 10, 2024
1 parent f593927 commit 86a4810
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion doc/user_guide/interactions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ where a drop-down is used to highlight cars of a specific ``Origin``:

.. altair-plot::

input_dropdown = alt.binding_select(options=['Europe','Japan','USA'], name='Region ')
input_dropdown = alt.binding_select(options=['Europe', 'Japan', 'USA'], name='Region ')
selection = alt.selection_point(fields=['Origin'], bind=input_dropdown)
color = alt.condition(
selection,
Expand Down Expand Up @@ -934,6 +934,27 @@ Another option to include an expression within a chart specification is as a val
param_width,
)

If we want our chart title to reflect the value from a selection parameter,
it is not enough to reference only the name of the parameter.
Instead, we need to explicitly include the field specified by the selection parameter
(i.e. ``Origin`` in the example below):

.. altair-plot::

input_dropdown = alt.binding_select(options=['Europe', 'Japan', 'USA'], name='Region ')
selection = alt.selection_point(fields=['Origin'], bind=input_dropdown, value='Europe')

title = alt.Title(alt.expr(f'"Cars from " + {selection.name}.Origin'))

alt.Chart(cars, title=title).mark_point().encode(
x='Horsepower:Q',
y='Miles_per_Gallon:Q',
).add_params(
selection
).transform_filter(
selection
)

Now that we know the basics of expressions,
let's see how we can improve on our search input example
and make the search string match via a regex pattern.
Expand Down

0 comments on commit 86a4810

Please sign in to comment.