-
-
Notifications
You must be signed in to change notification settings - Fork 831
Description
Hey all, I'd like to use altair to make interactive demos for teaching data science concepts. For teaching purposes, it would be really helpful to have some way of updating a chart's dataset after the initial render.
For example, we'd like to show a single histogram of sample means becoming narrower as the sample size #increases. We can do this using ipywidgets, but as described in #333 the chart flickers significantly. My hope is that just focusing on dataset changes rather than chart updates in general will be better scoped and easier to implement (I can offer my own time to work on this).
Based on Vega-lite's view.change method, I'm imagining something like:
data = alt.Data(values=[{'x': 'A', 'y': 5},
{'x': 'B', 'y': 3},
{'x': 'C', 'y': 6},
{'x': 'D', 'y': 7},
{'x': 'E', 'y': 2}])
chart = alt.Chart(data).mark_bar().encode(
x='x:O', # specify ordinal data
y='y:Q', # specify quantitative data
)
# later...
chart.change(alt.ChangeSet().insert({'x': 'F', 'y': 1}))
# and using ipywidgets:
def update(new_height):
chart.change(alt.ChangeSet().insert({'x': 'F', 'y': new_height}))
interact(update, new_height=(1, 10))Any opinions on this? I'm peeking at the altair and ipyvega code and this appears doable but not super easy. Maybe you'll have a better idea of how hard this will be.
cc @CalebS97