我想将某个图表中的所有Bokeh图形转换为链接到其他页面。这种可能吗?
例如,如果我有一个国家地图,每个国家都是一个补丁,如果用户点击一个国家,我希望将他们重定向到该维基百科页面。
在用户指南中,还有一个更简单的例子:
from bokeh.models import ColumnDataSource, OpenURL, TapTool
from bokeh.plotting import figure, output_file, show
output_file("openurl.html")
p = figure(plot_width=400, plot_height=400,
tools="tap", title="Click the Dots")
source = ColumnDataSource(data=dict(
x=[1, 2, 3, 4, 5],
y=[2, 5, 8, 2, 7],
color=["navy", "orange", "olive", "firebrick", "gold"]
))
p.circle('x', 'y', color='color', size=20, source=source)
url = "http://www.colors.commutercreative.com/@color/"
taptool = p.select(type=TapTool)
taptool.callback = OpenURL(url=url)
show(p)
OpenURL
回调函数的例子会有所帮助:https://github.com/bokeh/bokeh/blob/master/examples/models/colors.py - bigreddot