Update a Panel pane on selection of a node in hv.Graph

I am building a Panel app that is focused around a network graphs. I want to to select a node, which should initiate some computation and finally display result on a different panel pane.

Simplified prototype:

  • interactive plot displaying a network graph (hv.Graph)
  • hv.pane.Str to display index (indices?) of selected nodes

I started from the accepted answer here by ( philippjfr) and wrote the following code:

import hvplot.networkx as hvnx
import panel as pn
import numpy as np
import networkx as nx
import holoviews as hv
pn.extension()

np.random.seed(1)
G = nx.petersen_graph()

spring = hvnx.draw(G, with_labels=False)
stream_selection = hv.streams.Selection1D(source=spring.nodes)

@pn.depends(stream_selection.param.index)
def selection(index):
    return pn.pane.Str(f'Selected at {index}', width=200)


app = pn.Row(
    spring,
    selection
)
app

But this does not work… When I select a node – stream is not updated

Can someone advise whether I am doing anything wrong and how to achieve what I want?

1 Like

And I also found a related (unanswered) question here.
Indeed, when displaying only the nodes (i.e. spring.nodes), stream is updated as necessary.

app = pn.Row(
    #spring,
    spring.nodes,
    selection
)
app

But this does not seem a right way (including the dumb workaround proposed by the author of that question). Any suggestions?