Turn Bokeh Glyph into a link

萝らか妹 提交于 2019-12-10 10:08:26

问题


I would like to turn all of the Bokeh glyphs on a certain plot into links to other pages. Is this possible?

For example if I had a map of countries, each country as a patch, if a user were to click on a country I would like to redirect them to that wikipedia page.


回答1:


There also a simpler example in the User's Guide:

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)


来源:https://stackoverflow.com/questions/41511274/turn-bokeh-glyph-into-a-link

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!