I am unable to change ColumnDataSource
using select.callback
. The Column Names remain the same for all column data sources. Kindly let me know what I am doing wrong here.
This runs on the latest bokeh version 1.3.6
from math import pi
import pandas as pd
from bokeh.io import output_file, show,output_notebook
from bokeh.palettes import Category20c
from bokeh.plotting import figure
from bokeh.models import CustomJS, ColumnDataSource, Slider, Select
from bokeh.layouts import column
from bokeh.transform import cumsum
from bokeh.plotting import figure
from bokeh.models import ColumnDataSource,HoverTool,LinearInterpolator
output_notebook()
#STATE
y = {
'TamilNadu': 157,
'AP': 93,
'Mizoram': 89,
'Telangana': 63,
'Maharastra': 44,
'Karnataka': 42
}
state = pd.Series(y).reset_index(name='value').rename(columns={'index':'territory'})
state['angle'] = state['value']/state['value'].sum() * 2*pi
state['color'] = Category20c[len(y)]
state_cds = ColumnDataSource(state)
#COUNTRY
x = {
'United States': 157,
'United Kingdom': 93,
'Japan': 98,
'China': 127,
'Germany': 144,
'India': 90
}
country = pd.Series(x).reset_index(name='value').rename(columns={'index':'territory'})
country['angle'] = country['value']/country['value'].sum() * 2*pi
country['color'] = Category20c[len(x)]
country_cds = ColumnDataSource(country)
#name source for piechart(WEDGE)
source = state_cds
#####PLOTTING
pie_chart = figure(plot_height=350, title="Pie Chart", toolbar_location=None, x_range=(-0.5, 1.0))
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', source=source)
pie_chart.axis.axis_label=None
pie_chart.axis.visible=False
pie_chart.grid.grid_line_color = None
select = Select(options=['state', 'country'],value='state')
select.callback = CustomJS(args={"cds2": state_cds, "cds3": country_cds, "ls": pie_chart,"source" : source}, code="""
if(cb_obj.value === "state"){
ls.wedge.source.data = cds2.data
}
}else if(cb_obj.value === "country"){
ls.wedge.source.data = cds3.data
}
}
ls.change.emit();
""")
layout = column(select, pie_chart)
show(layout)
Technically this should produce a callback. I have tried the same thing with p.line and it works. Am I missing out on some java scripting or is my naming convention wrong?