I’m building Bokeh dashboard with country data to dynamically change graph for a line graph.
User are able to select multiple countries using CheckboxGroup.
I am able to subset source table dynamically as I select/deselect countries.
After I subset, I am aggregating source table for graph where problem occurs. (group all countries by date)
This is what I currently have:
we assume we define fig1
def make_plot(src):
temp = pd.DataFrame.from_dict(src.data)
agg_date_full = ColumnDataSource(temp.groupby('date').sum().reset_index())
fig1.line('date', 'y',source=agg_date_full)
def update(attr, old, new):
country_to_plot = [country_checkbox.labels[i] for i in country_checkbox.active]
new_src = make_dataset(country_to_plot)
src.data.update(new_src.data)
country_checkbox = CheckboxGroup(labels=country_labels, active= list(range(0,len(country_labels))))
country_checkbox.on_change('active', update)
initial_countries = [country_checkbox.labels[i] for i in country_checkbox.active]
src = make_dataset(initial_countries)
p = make_plot(src)
I understand that we have to directly use source=src
but I need to aggregate every time I update new source.
Is there any suggestion on how I can approach this issue?
I also created SO post as well.
Thanks!