3

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.

MRocklin
  • 55,641
  • 23
  • 163
  • 235

1 Answers1

5

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)
bigreddot
  • 33,642
  • 5
  • 69
  • 122