I am trying to achieve something similar to this example, except instead of using the slider to select discrete values, I would like it to serve as the cutoff point in a transform_filter (i.e. values < slider value).
Right now I have something like this:
import altair as alt
from altair.expr import datum
slider = alt.binding_range(min=data.refill_time.min().value,
max=data.refill_time.max().value,
step = 1)
select_date = alt.selection_single(name='refill_time',
fields=['refill_time'],
bind=slider)
refills = alt.Chart(data).mark_bar(
).transform_filter(
datum.refill_time < select_date.ref()
).encode(
alt.X('refill_count:Q',
alt.Y('group:N')
).add_selection(
select_date
)
display(refills)
I tried looking at the data from slider but I couldn't find any fields that return it's current value (.ref() attempt). I also tried changing the selection_single to _multi and _interval but I just got invalid specification errors - I couldn't find any way to define the binding_range that would make sense to the selection.
Is this possible in altair?
Try the following filter expression:
transform_filter(
"datum.refill_time < refill_time_refill_time"
)
where the strange looking "refill_time_refill_time" is build up by the selection name "refill_time" and the field name "refill_time". Although I am not 100% sure if thats correct, but in any case it should be the "slider text", so in the linked example it would be "year_year".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With