Hello!
Is it possible to somehow make fields in HoverTool disappear depending on the data inside?
Here is some example code
from bokeh.layouts import column
from bokeh.plotting import figure, curdoc
from bokeh.models import ColumnDataSource, Plot
import numpy as np
data = {
"x": [1,2,3],
"y": [1,2,3],
"flag": [True, False, False],
"extra_info": ["abc", None, None],
}
TOOLTIPS = [
("x", "@x"),
("y", "@y"),
("extra_info", "@extra_info"),
]
p = figure(width=300, height=300, tools="pan,reset,save,hover", tooltips=TOOLTIPS)
source = ColumnDataSource(data=data)
p.line(source=source)
doc = curdoc()
doc.add_root(column(p))
The hover tool in this example will show abc
under extra_info
for the first data point. For the second and third point it will show ???
under extra_info
.
My aim would be to make the extra_info
not appear at all for the points where it has no value. As you can see there is also a flag which correlates with the extra_info. Ideally, I would like to write custom JS that will decide what fields to show depending on the data inside. Something like:
if (point.flag) {
tooltips = [
("x", point.x),
("y", point.y),
("extra_info", point.extra_info)
]
} else {
tooltips = [
("x", point.x),
("y", point.y),
]
}
I can see that it is possible to create CustomJs Hover Tool as presented here JavaScript callbacks — Bokeh 2.4.0 Documentation but I have no idea what kind of attributes should I access to achieve the desired result. Would it be possible for some Bokeh pro to help with an example solution?