How ColumnDataSource and CDSView works together with from_networkx?

Hi!

I’m trying to visualize multilayer network created with networkx - each node has “layer” attribute and I want to create separate graph for each layer. I can do it like this:

def layer_graph_to_show(G,layer):
	
	layer_nodes = [n for n,attr in G.nodes(data=True) if attr["layer"]==layer]
	layer_subgraph = G.subgraph(layer_nodes)
	layout = {n:layer_subgraph.nodes[n]["coor"] for n in layer_subgraph.nodes()}
	graph = from_networkx(layer_subgraph,layout)

	return graph

This creates graph renderer with nodes from graph G in given layer. I can create plots for all layers and show them like this: (the code is a bit simplified)

plots =[]

for layer in layers:
	layer_graph_renderer = layer_graph_to_show(G,layer)
	
	layer_graph_plot = figure(title=layer,
				  x_range=(-1,1), y_range=(-1,1),
				  tools="lasso_select,pan,wheel_zoom")
	layer_graph_plot.renderers.append(layer_graph_renderer)

	plots.append(layer_graph_plot)
	
layout = gridplot(plots, ncols=2)
curdoc().add_root(layout)

But I want to add some custom callbacks (show and hide edges, change colors to selected nodes and its neighbors in all layres, …) and I don’t know how to do it. All callback examples I found works with ColumnDataSource, but what is the ColumnDataSource in graph renderer created by from_networkx?

I have also read about CDSView and I wonder if it will be better to use it instead of creating networkx subgraphs in my example - create only one graph from whole networkx graph and than filter nodes by layers. Again, I don’t know how to use CDSView at graph renderer.

Thank you for your answers,
Katerina