Chris Loonam
Chris Loonam

Reputation: 5745

Altair controlling one dropdown using another

I am using Altair to plot a dataset, and I am using selections to filter the data based on two criteria. I'll use the terms 'make' and 'model' (as in cars) to refer to these. These are not the actual names of the data, but the situation is analogous.

I'd like it so that, when a user selects a 'make' (let's say Cadillac), the 'model' dropdown will adjust its options to different Cadillac models (Escalade, CTS, etc.).

As it currently stands, I have two dropdowns successfully filtering the data using the following

make_dropdown = alt.binding_select(options=makes)
make_select   = alt.selection_single(fields=['make'], bind=make_dropdown, name='Make', init={'make': makes[0]})

model_dropdown = alt.binding_select(options=models)
model_select   = alt.selection_single(fields=['model_name'], bind=model_dropdown, name='Model', init={'model_name': models[0]})

However, the model_dropdown always shows every model for every make. After searching the Altair documentation, I can't find an easy way to filter its options based on make_select. Does anyone know how to do this?

Upvotes: 2

Views: 299

Answers (1)

jakevdp
jakevdp

Reputation: 86443

Vega-Lite currently (v4.12) provides no way to adjust the contents of one input binding based on the value selected in another input binding. If you want this behavior, you'll have to use something other than Altair/Vega-Lite.

Upvotes: 2

Related Questions