Hi all
I’m trying to get toggle buttons to load up different data sets in bokeh.
Currently I’ve got the two buttons to load up different data sets but they overwrite the existing data
I’d like it if the toggle buttons control if the data is plotted or not (using the toggle state).
Therefore in some cases I would have two lines plotted and in other cases just one line or no lines.
Have I gone about this in a totally wrong way?
I looked hiding the graphs using this example http://stackoverflow.com/questions/32253900/how-to-interactively-display-and-hide-lines-in-a-bokeh-plot
However in the end I’m going to have hundreds of buttons that display data when toggled on. So loading all the data then hiding it didn’t sound like a good idea.
Each of the data sets is stored in a simple two column text file but I’ve put in some random data till I figure out how to read fro a text file using Javascript
Many thanks
from bokeh.io import output_file, show, vform
from bokeh.models import CustomJS, ColumnDataSource, Slider
from bokeh.plotting import figure, output_file, show
from bokeh.models.widgets import Toggle
output_file(“callback.html”)
x = [0]
y = [0]
text_lable=’’
source1 = ColumnDataSource(data=dict(x=x, y=y,legend=text_lable))
plot = figure(plot_width=800, plot_height=400)
plot.line(‘x’, ‘y’, source=source, line_width=3, line_alpha=0.6,legend=“nothing yet”)
plot.yaxis.axis_label=“Cross section (barns)”
plot.xaxis.axis_label=“Energy (barns)”
callback_Ac_225_MT_102 = CustomJS(args=dict(source=source), code="""
var data = source.get(‘data’);
var f = 20
x = data[‘x’]
y = data[‘y’]
x[0]=100
y[0]=300
x[1]=250
y[1]=350
source.trigger(‘change’);
“”")
callback_Ac_225_MT_91 = CustomJS(args=dict(source=source), code="""
var data = source.get(‘data’);
x = data[‘x’]
y = data[‘y’]
console.log(x)
x[0]=15
y[0]=20
x[1]=22
y[1]=45
source.trigger(‘change’);
“”")
toggle_Ac_225_MT_102 = Toggle(label=“Ac_255_MT_102”, type=“success”,callback=callback_Ac_225_MT_102)
toggle_Ac_225_MT_91 = Toggle(label=“Ac_225_MT_91”, type=“success”,callback=callback_Ac_225_MT_91)
layout = vform(plot,toggle_Ac_225_MT_102,toggle_Ac_225_MT_91)
show(layout)