I'm working on a bokeh figure that shows cluster activity. When a user hovers over a particular processor, I want it to show statistics about the processor. Heres the code:
TOOLTIPS = [
("Usage", "@{usage}%"),
("Name", "@name"),
("PID", "@pid"),
("Command", "@command"),
("User", "@user"),
]
p = figure(title="Cluster Activity",
plot_width=1200,
plot_height=700,
x_range=nodes,
y_range=list(reversed(cores)),
tools='hover',
toolbar_location=None,
tooltips=TOOLTIPS
)
This works, but I don't want to show tooltips with a value of None. For example, if a particular processor, has a None value for User, the tooltip should not contain a user value, rather than showing "User : ???".
Is there any way to do this? I can't seem to find anything similar to this in the tutorials. I'd like to avoid writing custom JS.
I see two ways of doing this:
1. Checking if Name is None with Python and using multiple HoverTool
Since HoverTool is a bokeh.models.tools you can add it via
So you could make two instances of HoverTool and split your data to two data sources:
With the names attribute of HoverTool you can specify for which glyps the hover is rendered. I haven't tested the code.
2. Using custom JS (just mentioning for the sake of completeness)
In case you have many different combinations of possible missing values, I only see JS as a way to do this, have a look here: https://groups.google.com/a/continuum.io/forum/#!msg/bokeh/4VxEbPaLqnA/-qYLDsbZAwAJ
You can also create the tooltips dynamically using JS callback attached to the
HoverTool
(Bokeh 1.1.0)Result: