Skip to content

How to set alt.selection_point to allow one and only one option to be selected at a time (similar to a radio button filter) #3230

Answered by binste
chrisHassan asked this question in Q&A
Discussion options

You must be logged in to vote

You can set toggle=False within alt.selection_point:

import altair as alt
import pandas as pd
# now we get base per a position
chart_df = pd.DataFrame(dict(
    category=list('abcde')
    , n=list(range(1,6))
))

# note, alt.selection_single didn't work for me either, and also get a deprecation warning
# to use alt.selection_point
category_selected = alt.selection_point( 
    fields=['category'],
    value=[{'category': 'e'}],
    toggle=False
)                                     

category_chart_filter = alt.Chart(chart_df).mark_bar().encode(
     x=alt.X('category', sort='-y')
    ,y='n'
    ,color='category'
    ,opacity=alt.condition(category_selected, alt.value(1), alt.value(0.2))
).a…

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by binste
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants