As of Bokeh 0.12.6
, being able to make these kinds of "Remote Procedure Calls" is still an open feature request.
In the mean time, your best bet is to add a CustomJS
callback to some property of some model. The CustomJS
can execute whatever JS code you want (including calling other JS functions) and will trigger any the property is updated.
Here's an example that shows calling CustomJS
whenever a slider is changed. For your use case you might add an invisible circle glyph, and attach a CustomJS
to the glyph's size
attribute. Changing glyph.size
is how you can "call" the function.
from bokeh.layouts import column
from bokeh.models import CustomJS, ColumnDataSource, Slider
from bokeh.plotting import Figure, output_file, show
output_file("js_on_change.html")
x = [x*0.005 for x in range(0, 200)]
y = x
source = ColumnDataSource(data=dict(x=x, y=y))
plot = Figure(plot_width=400, plot_height=400)
plot.line('x', 'y', source=source, line_width=3, line_alpha=0.6)
callback = CustomJS(args=dict(source=source), code="""
var data = source.data;
var f = cb_obj.value
x = data['x']
y = data['y']
for (i = 0; i < x.length; i++) {
y[i] = Math.pow(x[i], f)
}
source.change.emit();
""")
slider = Slider(start=0.1, end=4, value=1, step=.1, title="power")
slider.js_on_change('value', callback)
layout = column(slider, plot)
show(layout)