CustomJS on Hover with GraphRenderer


I posted this question already on StackOverflow (link), but it might fit better in this group.

For my dashboard, I am using networkx to plot a graph:

import networkx as nx
from bokeh.models.graphs import from_networkx
p_network = figure(title="Correlation",
               plot_width=400, plot_height=400,
               tools='', toolbar_location=None)
graphNX = from_networkx(graph, nx.circular_layout, scale=1, center=(0,0))


I want to add a callback function to be executed whenever the user hovers over one of the nodes.

This function should later change the color of points in a different plot, but for testing purposes I let it print “hello” to the console

code = """console.log('hello');"""
args = {"nodes": graphNX.node_renderer.data_source, "edges":  graphNX.edge_renderer.data_source}
callback = CustomJS(args=args, code=code)
hover_tool = HoverTool(tooltips=None,callback=callback)


This is not working and leads to following error: “TypeError: n.data_source is undefined”

There is probably something wrong in how I define args, resp. in how I add the data_sources.

A similar code is working, when I try it with a different kind of plot:

points ="lon", y="lat", size=10, source=src)
args = {"points": points.data_source}


But I can not find out how to refer to the data_source of my network plot correctly.

I would be grateful for every hint I can get.

Kind regards,