首先,伟大的网站,伟大的人。你们都对我的学习帮助很大。谢谢!
我在使用Bokeh和浏览器时遇到了问题。特别是,我正在尝试让Javascript回调在Bokeh中工作。
我从这个网站下载了这个示例代码
https://docs.bokeh.org/en/latest/docs/user_guide/interaction/callbacks.html。
该网站包含一个使用套索工具的示例。
代码在网站上运行得很好,但当我将代码复制到Python中并亲自运行它时,JS回调就不起作用了。套索工具部分工作正常。我试过在IE,Chrome,Firefox,工作电脑和家用电脑上运行这个程序。
一般来说,我对Javascript不是很在行,所以对这个问题的任何见解都将非常感谢。
提前干杯并致谢。
代码来自以下网站:
from random import random
from bokeh.layouts import row
from bokeh.models import CustomJS, ColumnDataSource
from bokeh.plotting import figure, output_file, show
output_file("callback.html")
x = [random() for x in range(500)]
y = [random() for y in range(500)]
s1 = ColumnDataSource(data=dict(x=x, y=y))
p1 = figure(plot_width=400, plot_height=400, tools="lasso_select", title="Select Here")
p1.circle('x', 'y', source=s1, alpha=0.6)
s2 = ColumnDataSource(data=dict(x=[], y=[]))
p2 = figure(plot_width=400, plot_height=400, x_range=(0, 1), y_range=(0, 1),
tools="", title="Watch Here")
p2.circle('x', 'y', source=s2, alpha=0.6)
s1.callback = CustomJS(args=dict(s2=s2), code="""
var inds = cb_obj.selected['1d'].indices;
var d1 = cb_obj.data;
var d2 = s2.data;
d2['x'] = []
d2['y'] = []
for (i = 0; i < inds.length; i++) {
d2['x'].push(d1['x'][inds[i]])
d2['y'].push(d1['y'][inds[i]])
}
s2.change.emit();
""")
layout = row(p1, p2)
show(layout)
发布于 2017-08-31 03:31:18
问题是bokeh版本的不同,您使用的是版本0.12.4。在bokeh版本0.12.4中,要注册列数据源中的更改,需要使用语法source.change('trigger').
文档的最新版本(也就是您引用的示例的出处)上的示例使用版本0.12.6。从bokeh版本0.12.6开始,它已经贬值了,语法现在变成了source.change.emit()
。
https://stackoverflow.com/questions/45972095
复制相似问题