Hello,
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,
x_range=(-2,2),y_range=(-2,2),
tools='', toolbar_location=None)
graph=nx.Graph(df)
graphNX = from_networkx(graph, nx.circular_layout, scale=1, center=(0,0))
p_network.renderers.append(graphNX)
``
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)
p_network.add_tools(hover_tool)
``
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 = p.circle(x="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,
SL