Separate HoverTool for nodes and edges in graph

Hi!

I have similar problem as mentioned in an older question: Hover-over tooltips on network edges. I want to create separate HoverTool tooltips for edges and nodes in graph created in networkx. I have also found this solution on Stack Overflow https://stackoverflow.com/questions/53331902/separate-node-and-edge-hover-tools-in-bokeh.

I’m trying to add HoverTool to the nodes and edges renderers, but it does not work and I don’t know why. Here is an example:

import networkx as nx
from bokeh.plotting import figure, curdoc, from_networkx
from bokeh.models import HoverTool

# create networkx graph
g = nx.Graph()
g.add_nodes_from([(4,{"sheet":"A","coor":(2,1)}),
				  (5,{"sheet":"A","coor":(2,2)}),
				  (6,{"sheet":"A","coor":(3,1)}),
				  (7,{"sheet":"A","coor":(3,2)})])

g.add_edges_from([(4,5,{'weight':1, 'delay':1}),
				  (5,6,{'weight':1, 'delay':1}),
				  (4,6,{'weight':1, 'delay':1}),
				  (6,7,{'weight':1, 'delay':1})])

layout = {n:g.nodes[n]["coor"] for n in g.nodes()}

# create graph renderer from networkx graph
graph_renderer = from_networkx(g,layout)
 
plot = figure(x_range=(1,4), y_range=(0,3),
			  tools="lasso_select,pan,wheel_zoom")

# hover tools for edges and nodes
hover_nodes = HoverTool(
				tooltips=[("index", "@index"), ("coordinates", "@coor")],
				renderers=[graph_renderer.node_renderer]
				)

hover_edges = HoverTool(
				tooltips=[('weight','@weight'),('delay','@delay')],
				renderers=[graph_renderer.edge_renderer]
				)

plot.add_tools(hover_edges,hover_nodes)

plot.renderers.append(graph_renderer)
curdoc().add_root(plot)

Do you know how to solve it?

Thank you,
Katerina