Unbind a dynamicmap or bound function?

In my app I have a DynamicMap defined like this: dmap = hv.DynamicMap(pn.bind(make_dmap, input1=widget1, input2=widget2)) with widget1 and widget2 being already defined at module-level.

Then I have a callback that replaces this DynamicMap with another in the layout using new data, but the same widgets are used to drive the new plot. These widgets are first reinitialised. In the past, my DynamicMap was still bound to these widgets so during the callback it would get updated first with the reinitialised values before being replaced, leading to useless computation/rendering and delays for the user.

Therefore I looked for a way to unbind a DynamicMap. I finally found the following pretty contrived solution.

First record all the widgets driving the DynamicMap: dmap_streams = dmap._streams_param_value[0]._rename.keys()

And then unwatch the streams:

for stream in dmap_streams:
    while len(stream[0]._param_watchers[stream[1]]['value']) > (1 if not isinstance(stream[0], pnw.Player) else 2):

Is there a simpler and more elegant way to unbind a DynamicMap or a pn.bind?

1 Like