0

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.

Community
  • 1
  • 1
jim jarnac
  • 4,804
  • 11
  • 51
  • 88

2 Answers2

2

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)
Luke Canavan
  • 2,107
  • 12
  • 13
  • no i don't think so. This is the correct way as per the documentation: http://bokeh.pydata.org/en/latest/docs/user_guide/interaction/callbacks.html#openurl – jim jarnac Apr 07 '17 at 18:27
  • It looks like that part of the user guide is out-of-date (it's not super clear to me why the example works). Here's the reference docs though: http://bokeh.pydata.org/en/latest/docs/reference/models/plots.html#bokeh.models.plots.Plot.select – Luke Canavan Apr 07 '17 at 18:39
  • 1
    This does not seem to work with Bokeh 0.13.0 says ```str has no attribute append``` – unlockme Oct 18 '18 at 14:59
0

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.

unlockme
  • 3,897
  • 3
  • 28
  • 42