截至 Bokeh 0.12.6,能够进行此类“远程过程调用”仍然是 open feature request。
同时,最好的办法是在某些模型的某些属性中添加CustomJS callback。 CustomJS 可以执行任何你想要的 JS 代码(包括调用其他 JS 函数)并且会触发任何属性的更新。
这是一个示例,它显示每当更改滑块时调用CustomJS。对于您的用例,您可以添加一个不可见的圆形字形,并将CustomJS 附加到字形的size 属性。更改glyph.size 是您可以“调用”该函数的方式。
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)