Python Bokeh服务器:无法将回调连接到图示符点击,例如圆形?
我一直在尝试在单击glyph时调用python函数。我已经尝试了这个例子和这个,但我的回调始终没有被调用。这是我的密码Python Bokeh服务器:无法将回调连接到图示符点击,例如圆形?,python,bokeh,Python,Bokeh,我一直在尝试在单击glyph时调用python函数。我已经尝试了这个例子和这个,但我的回调始终没有被调用。这是我的密码 from bokeh.models import Slider, ColumnDataSource from bokeh.io import curdoc from bokeh.layouts import row from bokeh.plotting import figure from bokeh.palettes import d3 from numpy.random
from bokeh.models import Slider, ColumnDataSource
from bokeh.io import curdoc
from bokeh.layouts import row
from bokeh.plotting import figure
from bokeh.palettes import d3
from numpy.random import random
#Create data for the plot
initial_points = 5
data = {'x': random(initial_points),
'y': random(initial_points)
}
source = ColumnDataSource(data = {'x': random(initial_points), 'y': random(initial_points)})
plot = figure(title = "Random scatter plot generator", plot_height=750, plot_width=750,
tools="tap")
plot.circle(x = 'x', y = 'y', source = source, color='green', size=20, alpha=0.5)
slider_widget = Slider(start = 0, end = 20, step = 2, value = initial_points, title = 'Slide
right to increase number of points')
def slider_callback(attr, old, new):
points = slider_widget.value
source.data = {'x': random(points), 'y': random(points)}
slider_widget.on_change('value', slider_callback)
def tap_callback(attr, old, new):
print('Here mate')
source.on_change('selected', tap_callback)
layout = row(slider_widget, plot)
curdoc().add_root(layout)
所讨论的回调函数是点击_callback。
我真的很想看到在点击一个标志符号后在终端上打印“Here mate”Replace
source.on\u更改('selected',点击\u回调)
与
source.selected.on\u更改('index',点击\u回调)
更换
source.on\u更改('selected',点击\u回调)
与
source.selected.on\u更改('index',点击\u回调)
如果源是一个图形.节点\u渲染器.数据\u源怎么办?
?它不是…唯一可用的属性是所选的属性,而不是索引
属性。这是行不通的。“唯一可用的属性是selected
属性”-但这正是我的答案建议使用的吗?它应该是graph.node\u renderer.data\u source.selected.on\u change('index',tap\u callback)
well我指的是on\u change
方法的第一个参数。我终于在这里找到了答案。我不明白你的意思。第一个参数是'index'
,它非常适合我使用最新Bokeh版本的图形。但我很高兴您能以任何一种方式运行它。如果源代码是一个图形、节点、渲染器、数据\u源
?它不是…唯一可用的属性是选定的
属性,而不是索引
属性。这是行不通的。“唯一可用的属性是selected
属性”-但这正是我的答案建议使用的吗?它应该是graph.node\u renderer.data\u source.selected.on\u change('index',tap\u callback)
well我指的是on\u change
方法的第一个参数。我终于在这里找到了答案。我不明白你的意思。第一个参数是'index'
,它非常适合我使用最新Bokeh版本的图形。但我很高兴你让这两种方式都起作用了。