将 Bokeh 图形转换为链接

3

我想将某个图表中的所有Bokeh图形转换为链接到其他页面。这种可能吗?

例如,如果我有一个国家地图,每个国家都是一个补丁,如果用户点击一个国家,我希望将他们重定向到该维基百科页面。


也许这个使用OpenURL回调函数的例子会有所帮助:https://github.com/bokeh/bokeh/blob/master/examples/models/colors.py - bigreddot
@bigreddot,您提供的链接返回404错误页面,希望能够好好查看一下。 - unlockme
更新后的URL: https://github.com/bokeh/bokeh/blob/master/examples/models/file/colors.py - bigreddot
1个回答

5

用户指南中,还有一个更简单的例子:

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)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接