Reputation: 5152
Hi have a timeserie to which I add circle glyphs, representing 2 different type of data.
I already managed to assign a different tooltip to each of them by using the suggestion presented here: https://stackoverflow.com/a/37558475/4961888
I was hoping I could use a similar syntax to assign a specific subset of the glyph to a taptool, that would bring me to a url present in the source of those glyphs.
so I tried:
fig = figure(x_axis_type="datetime", height=200, tools="tap")
fig.line(x_range, y_range)
news_points = fig.circle(x='timestamp', y='y', fill_color="green", size=5, source=news_source)
url = "@url"
taptool = fig.select(type=TapTool)
taptool.renderers.append(news_points)
taptool.callback = OpenURL(url=url)
But i receive:
AttributeError: '_list_attr_splat' object has no attribute 'renderers'
It seems to me that the taptool has a different way of being assigned glyphs than the hovertool, and I couldn't find any documentation on the web regarding my problem. I would be glad if someone with a better grip of the package could help me wrap my head around it.
Upvotes: 0
Views: 675
Reputation: 4245
If you are using bokeh 0.13.0 you achieve this by assigning the renderers as a list. Instead of taptool.renderers.append(glyph)
You can do taptool.renderers= [glyph,]
Something along the lines
fig = figure(x_axis_type="datetime", height=200, tools="tap")
fig.line(x_range, y_range)
news_points = fig.circle(x='timestamp', y='y', fill_color="green", size=5,
source=news_source)
url = "@url"
taptool = fig.select(type=TapTool)[0]
taptool.renderers= [news_points,]
taptool.callback = OpenURL(url=url)```
Otherwise you might get an extra error str has no attribute append
From the documentation renderers can also accept a list, This is especially important where you have multiple renderers on the graph otherwise it takes all the renderers on the plot.
Upvotes: 0
Reputation: 2137
fig.select
returns a list, so you'll want to access the first (and only, I'd assume) element.
fig = figure(x_axis_type="datetime", height=200, tools="tap")
fig.line(x_range, y_range)
news_points = fig.circle(x='timestamp', y='y', fill_color="green", size=5, source=news_source)
url = "@url"
taptool = fig.select(type=TapTool)[0]
taptool.renderers.append(news_points)
taptool.callback = OpenURL(url=url)
OR
fig = figure(x_axis_type="datetime", height=200, tools="tap")
fig.line(x_range, y_range)
news_points = fig.circle(x='timestamp', y='y', fill_color="green", size=5, source=news_source)
url = "@url"
taptool = fig.select_one(TapTool)
taptool.renderers.append(news_points)
taptool.callback = OpenURL(url=url)
Upvotes: 2