An example with a radio group callback, that the best way I found to reset when changing graphs is to simply get a range of data and set it to a range:
from bokeh.plotting import Figure from bokeh.models import ColumnDataSource, CustomJS, RadioGroup from bokeh.layouts import gridplot from bokeh.resources import CDN from bokeh.embed import file_html x0 = range(10) x1 = range(100) y0 = [i for i in x0] y1 = [i*2 for i in x1][::-1] fig=Figure() source1=ColumnDataSource(data={"x":[],"y":[]}) source2=ColumnDataSource(data={"x0":x0,"x1":x1,"y0":y0,"y1":y1}) p = fig.line(x='x',y='y',source=source1) callback=CustomJS(args=dict(s1=source1,s2=source2,px=fig.x_range,py=fig.y_range), code=""" var d1 = s1.get("data"); var d2 = s2.get("data"); var val = cb_obj.active; d1["y"] = []; var y = d2["y"+val]; var x = d2["x"+val]; var min = Math.min( ...y ); var max = Math.max( ...y ); py.set("start",min); py.set("end",max); var min = Math.min( ...x ); var max = Math.max( ...x ); px.set("start",min); px.set("end",max); for(i=0;i<=y.length;i++){ d1["y"].push(d2["y"+val][i]); d1["x"].push(d2["x"+val][i]); } s1.trigger("change"); """) radiogroup=RadioGroup(labels=['First plot','Second plot'],active=0,callback=callback) grid = gridplot([[fig,radiogroup]]) outfile=open('TEST.html','w') outfile.write(file_html(grid,CDN,'Reset')) outfile.close()
The Bokeh website lacks examples for different ways to set callbacks for different widgets.
Seb
source share