Imagine I have 2 (or more) sources of data with the same number of columns and rows:
#Data
dates = [date(2016, i, 1) for i in range(1,13)]
data1 = pd.DataFrame(index = dates, data = random.randn(12, 2),
columns = ['A', 'B'])
data2 = pd.DataFrame(index = dates, data = random.randn(12, 2),
columns = ['A', 'B'])
and I want to plot columns A & B in bokeh as so:
#Bokeh
source = ColumnDataSource(source1)
source1 = ColumnDataSource(data1)
source2 = ColumnDataSource(data2)
p = figure(x_axis_type = 'datetime')
l1 = p.line(source = source, x = dates, y= 'A', color = 'Red')
l2 = p.line(source = source, x = dates, y= 'B', color = 'Blue')
and I have a dropdown list:
select = Select(options = ['source1', 'source2'], value = 'source1')
What's the easiest way to create a callback for select so that the source of data in the line charts change as a different option is chosen in the dropdown list? I have little to no experience in JS and can't really wrap my head around callbacks so any help would be appreciated.
Edit:
I've tried this:
codes = """
var f = cb_obj.get('value');
var sdata = source.data;
var 1data = source1.data;
var 2data = source2.data;
if (f == "source1") {
sdata = 1data ;
source.trigger('change');
};
if (f == "source2") {
sdata = 2data ;
source.trigger('change');
};
"""
select.callback= CustomJS(args= dict(source = source, source1=source1,
source2=source2), code = codes)
But it doesn't work...