Skip to content

Binding select_single to functions #2463

Closed Answered by joelostblom
erlebach asked this question in Q&A
Discussion options

You must be logged in to vote

Combining from this and this docpage, you could do something like:

from vega_datasets import data
import altair as alt

dropdown = alt.binding_select(
    options=['median_acc', 'mean_acc'],
    name='X-axis column '
)
xcol_param = alt.param(
    value='mean_acc',
    bind=dropdown
)
cars = data.cars()
alt.Chart(cars, title=alt.Title(alt.expr(xcol_param.name))).mark_bar().encode(
    y='Cylinders:O',
    x=alt.X('selected_column:Q').title(None)
).transform_aggregate(
    mean_acc='mean(Acceleration)',
    median_acc='median(Acceleration)',
    groupby=["Cylinders"]
).transform_calculate(
    selected_column=f'datum[{xcol_param.name}]'
).add_params(
    xcol_param
)

Replies: 3 comments 6 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@joelostblom
Comment options

Answer selected by mattijn
@SeeBastion156
Comment options

@joelostblom
Comment options

Comment options

You must be logged in to vote
3 replies
@mattijn
Comment options

@ChristopherDavisUCI
Comment options

@SeeBastion156
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
6 participants