-
Notifications
You must be signed in to change notification settings - Fork 796
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 blank dropdown option that doesn't filter #2096
Comments
It's a bit hacky, but this works: alt.Chart(cars).mark_point().encode(
x='Horsepower:Q',
y='Miles_per_Gallon:Q',
color='Origin:N',
tooltip='Name:N'
).add_selection(
selection
).transform_filter(
f"({selection.Origin}[0] == 'All') || ({selection.Origin}[0] == datum.Origin)"
) It would be nice to update the altair expression syntax so that this condition could be written like this instead: (selection.Origin[0] == 'All') | (selection.Origin[0] == alt.datum.Origin) |
Looks like adding |
Oh, sorry, you have to use selection names that are valid identifiers. Try this: import altair as alt
from vega_datasets import data
cars = data.cars.url
input_dropdown = alt.binding_select(options=['All','Europe','Japan','USA'], name="Country")
selection = alt.selection_single(fields=['Origin'],
bind=input_dropdown,
init={'Origin': 'Europe'})
alt.Chart(cars).mark_point().encode(
x='Horsepower:Q',
y='Miles_per_Gallon:Q',
color='Origin:N',
tooltip='Name:N'
).add_selection(
selection
).transform_filter(
f"({selection.Origin}[0] == 'All') || ({selection.Origin}[0] == datum.Origin)"
) |
Awesome - thanks! |
@ZaxR I am going through Altair issues to find those that have been resolved and can be closed. It looks to me like this issue has been solved so I am closing it, but please feel free to reopen and add a comment if there is something you don't think is resolved yet. |
I have a chart with a dropdown selector, and the selection is responsible for filtering the data displayed in the chart. I'm trying to add a "blank" option to the binding_select that will result in no filtering (i.e. "display all data"). Is there an easy way to do that?
I was looking at alt.condition and filter predicates, but wasn't able to figure it out. I was playing with the following example, where i'd want an "All" selection in the binding_select:
Thanks for the library and for the help!
The text was updated successfully, but these errors were encountered: