Skip to content Skip to sidebar Skip to footer

Python Bokeh - Assign Taptool To A Subset Of Glyphs

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 p

Solution 1:

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)

Solution 2:

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.


Post a Comment for "Python Bokeh - Assign Taptool To A Subset Of Glyphs"