I have started bokeh JS callback and it is not able to interact properly with my piechart callback. The new piechart of years is not displayed despite the callback. An identical code has work for barcharts. The angles and colors have been provided as lists in the df.
I have two options in my dropdown list and have assigned a seperate .wedge() to each month and year. Have tried assigning callback in the JS form. The pie_chart_month overrides pie_chart_year and that is the only reason why this is displayed
#data for years(df_year)
# index years counts angle color
#0 1 2013 1267562 2.712785 #99d594
#1 2 2014 1055861 2.259711 #ffffbf
#2 3 2015 612426 1.310689 #fc8d59
# data for months(df_months)
# . index months counts angle color
#0 1 Jan 4562 2.712785 #99d594
#1 2 Feb 2414 2.259711 #fffbbf
#2 3 Mar 4234 1.310689 #fc8d59
#
#
#------------------
pie_chart = figure(plot_height=350, title="Pie Chart", toolbar_location=None,
tools="hover", tooltips=[("Counts", "@counts")])
pie_chart_year = pie_chart.wedge(x=0, y=1, radius=0.4,
start_angle=cumsum('angle', include_zero=True),
end_angle=cumsum('angle'),
line_color="white", fill_color='color', legend='years', source=df_year)
pie_chart_month = pie_chart.wedge(x=0, y=1, radius=0.4,
start_angle=cumsum('angle', include_zero=True), end_angle=cumsum('angle'),
line_color="white", fill_color='color', legend='months', source=df_month)
source_pie_month = ColumnDataSource(df_month)
source_pie_year = ColumnDataSource(df_year)
#callback for input controls
pie_chart_callback = CustomJS(args=dict(months=source_pie_month, years=source_pie_month, plot=pie_chart), code="""
if (ui_view1.value=="months") {
plot.factors = months.data_source.data.months
} else {
plot.factors = years.data_source.data.years
}
plot.change.emit()
""")
ui_view1 = Select(title="View", callback=pie_chart_callback, value="months", options=["months", "years"])
ui_view1.js_on_change('value', pie_chart_callback)
# layout
layout = column(ui_view1, pie_chart)
show(layout)
Expected Result: The piechart month would change to the month when month
is selected. Piechart year would change to year if year
is selected