python - 散景服务器:无法将回调附加到字形点击,例如圆圈?
问题描述
单击字形时,我一直在尝试调用 python 函数。我试过这个例子https://stackoverflow.com/a/50499396/8925535和这个https://groups.google.com/a/continuum.io/g/bokeh/c/zVzLyvJFWtE/m/eRugLfUuAAAJ但仍然我的回调永远不会被调用。这是我的代码
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)
有问题的回调函数是tap_callback。单击字形后,我真的很想在终端中看到“Here mate”
解决方案
代替
source.on_change('selected', tap_callback)
和
source.selected.on_change('indices', tap_callback)
推荐阅读
- python - 使用置信区间可视化 2D 嵌入
- c - 从特定地址初始化多维数组指针的正确方法
- python - 需要一个条件语句来填充基于字符串的列
- azure-devops - Azure DevOps 无法从其自己的存储库下载工件
- php - 如何在选择中显示分组项目?
- android - 将数字四舍五入到下一个最高的位置
- node.js - 默认 Firebase 应用不存在。确保在使用任何 Firebase 服务之前调用 initializeApp()。在 FirebaseAppError
- node.js - 无法通过 REST API 访问使用 Mongodb 部署的 Nodejs 应用程序
- php - 如何每 5 秒更新一次显示的用户的离线、在线状态?
- java - Java - poi:将一个 docx 附加到另一个 docx 时出现问题:使用未定义的命名空间 > 前缀:w15