Considering the example below from the Bokeh Docs, is there a way to adjust the TapTool so that when I click on a circle I'm taken to the url on the same tab rather than opening a new tab? The docstring suggests that the only behavior is to open a new tab, but perhaps there's a CustomJS workaround or some other hack to get around this?
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)
I wrapping some javascript without success (borrowing from this question but kind of clueless on how exactly to implement it). This results in no link opening:
callback = CustomJS(args=dict(source=source), code="""
url = data['url']
window.open(url,"_self");
""")
taptool = p.select(type=TapTool)
taptool.callback = callback
I also tried treating the link like an <a>
tag using the tag
keyword for OpenURL. This is a blind attempt since I could not find anything on how to use this tag
term properly. No luck here.
url = "http://www.colors.commutercreative.com/@color/"
taptool = p.select(type=TapTool)
taptool.callback = OpenURL(url=url, tags=["_self"])
I understand Bokeh is still pretty new so perhaps this functionality isn't available yet. I still think there's got be a workaround if you know enough javascript (which I apparently don't).