How to force an update of the HoverTool

Hi again, sorry for posting another question already.

I was wondering how I can forcibly refresh the values shown by the hover tool?
E.g. the hover tool displays outdated data when the datasource is changed but the mouse has not been moved.
I wasn’t able to find an API entry point.

Example(from the gallery):
Gapminder

Thank you in advance

@kaprisonne I am afraid there is no mechanism to do that. The assumption with the hover tool has always been that mouse movements are frequent, so it only update on mouses moves, and there is no API to make it behave differently. As an alternative you might consider putting a Div next to the plot and update the contents of that Div with the information you want to display, instead of using a hover tool.

@Bryan Uff, that’s a pity. Seems like I’m really pushing bokeh to its (intended) limit.
I suppose a workaround has to do then.
What exactly do you mean with “putting a Div next ot the plot”?
Something like saving the last mouse position (specifically the data_source-indice) and whenever I change the datasource I retrieve the value at said indice and show it on the div?
Would there be a way to link this to the value shown next to the mouse pointer/hover tool? I really would like the information to be as close to the mouse pointer (and the users attention area) as I can

I really would like the information to be as close to the mouse pointer (and the users attention area) as I can

Besides a Div next to the plot, you could also use a text glyph or Label annotation to draw directly on the canvas. If you can require users to actually click on the point that they want to interrogate, that will be much simpler. Clicking will set the the selection index in the source.selected.indices property. Then a callback for the data source change could just look there to get the necessary index needed update the Div, text or label as appropriate.

There’s probably a roundabout way to do it with hover only, but it would not be pretty, since inspection information is not currently publicly available. You would have to make a HoverTool.callback to set the inspection indices on a new DataModel (Bokeh >=2.3 only), and then the data source callback could look at the DataModel get the index of the hovered point.

A reasonable GitHub Issue here would be regarding making the hover inspection hit-testing public, which would make same (simpler) solutions as for selections possible. We have not done so yet because, done naively, it would result in excessive data updates (i.e. every single mouse move). But the information is there, so we would just need to find some way to be more clever about it, or at least only turned on when explicitly asked.

Seems like I’m really pushing bokeh to its (intended) limit.

There’s an infinite amont of things that could be implemented. So most development is driven off of expressed user need, and no one has ever asked for this before. But speaking frankly, I’d have to say it’s unlikely we would consider API to trigger mouse hovertool updates manually, even if asked:

  • very uncommon need (low user impact / benefit)
  • very hard to test (high maintenance burden)

This combination is about the worst-case scenario for any potential feature ask.

What is much more likely is to add a “sticky” tooltip option that can be completely manually controlled by users:

Feature Request: HoverTool tooltips stick to a point on click. · Issue #5724 · bokeh/bokeh · GitHub

There is clear interest and utility in this, but there’s been a lot of discussion and back and forth and not enough agreement, so nothing has been done yet.