Recommendations for rendering HVNX graph in Panel with "run" button?

Hi there. I’m new to Panel , HoloViz, and NetworkX and am trying to produce a Panel app that will render and update a HvPlot NetworkX graph as efficiently as possible.

I’d say the heaviest task I’m trying to accomplish at the moment is drawing a graph, and then attempting to highlight nodes based on user selections.

Here’s a very simplified version of a working example:

import networkx as nx
import hvplot.networkx as hvnx
import panel as pn
pn.extension(sizing_mode="stretch_width")

G = nx.DiGraph([(0,3),(1,3),(2,4),(3,5),(3,6),(4,6),(5,6),(6,7),(8,6)])

def draw_graph(G_in, nodes_of_interest=[]):
    
    color_map = []
    for node in G_in.nodes:
        if node in nodes_of_interest:
            color_map.append('red')
        else:
            color_map.append('blue')
            
    pos = nx.spring_layout(G_in)
    graph = hvnx.draw(G_in, pos, node_color=color_map)
    return graph

node_selector = pn.widgets.MultiChoice(options=sorted(list(G.nodes)),
                                      name = "Select your node(s) of interest",
                                      sizing_mode="stretch_both",
                                      )

bound_draw_graph = pn.bind(draw_graph, G_in=G, nodes_of_interest=node_selector)

app = pn.template.MaterialTemplate(
    title="Highlight Nodes",
    sidebar = [node_selector],
    main = [pn.Column(bound_draw_graph),]
).servable()

In reality, I am working with much larger graphs and doing quite a bit more processing between the user-selected nodes and the drawing of the graph with a color_map. But I think this example will work.

What I’m finding is that it can take quite sometime for the new graph to render.

I’d like to implement some kind of ‘run’ button that the user can hit after they’ve made all of their widget selections (to avoid re-rendering as they’re making more and more widget selections). Thinking that will help a lot with the efficiency of the app.

I’ve come across a few threads breaking down how to do this using param.watch() and/or button.on_click(), but for the life of me I’ve not been able to get this to work with HVNX graphs. (This is most certainly just a gap in my knowledge).

I wanted to ask if anyone has any recommendations on how to accomplish this?

And/or if you have any examples of folks working with HvPlot NetworkX in Panel I’d sure appreciate you pointing me in their direction. Been doing quite a bit of searching without a ton of results. Thanks in advance for any and all help!