Hi,
I’m quite new to bokeh and im trying to change de datasource of my wedge by giving it a element from a list based on the index var selected_index = cb_data.source.selected.indices[0];. But when I try pie.data_source = source_list[selected_index]; it doest work. I would like to know if this is possible or not. In the end I would like to run it with bokeh serve.
—Code— version 3.0.2
from bokeh.models import ColumnDataSource
from bokeh.transform import cumsum
from bokeh.palettes import Category10
from bokeh.plotting import figure, show
from bokeh.layouts import row
from random import randint
import pandas as pd
from math import pi
def maybe():
source_list = []
for key, value_ in z.items():
data = pd.Series(value_).reset_index(name='value').rename(columns={'index': 'country'})
data['angle'] = data['value']/data['value'].sum() * 2*pi
data['color'] = Category10[len(value_)]
source_list.append(ColumnDataSource(data))
return source_list
source_list = maybe()
source_bars = ColumnDataSource({'x': [1, 2, 3, 4, 5], 'y': [3,3,3,3,3]})
p = figure(height = 500, width = 800, tools = 'tap')
bars = p.vbar(x = 'x', top = 'y', source = source_bars, bottom = 0, width = 0.2)
p2 = figure(height = 500, width = 800)
pie = p2.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_list[0])
# pie.visible = False
p2.axis.axis_label = None
p2.axis.visible = False
p2.grid.grid_line_color = None
code = '''if (cb_data.source.selected.indices.length > 0){
pie.visible = true;
var selected_index = cb_data.source.selected.indices[0];
pie.data_source = source_list[selected_index];
pie.data_source.change.emit();
}'''
plots = row(p, p2)
p.select(TapTool).callback = CustomJS(args = {'pie': pie, 'source_list': source_list}, code = code)
show(plots)
Thanks in advanced.