Dynamic Map unable to switch between some cases

Hello,

below I’ve implemented a graph in which I want to change two graph attributes based on a selection in a dynamic map.
For illustration purposes, I’ve used a graph with two nodes and one connecting edge. I want to be able to change the edge- and node color freely between green and black.

The issue is the following:
When the node color is set to ‘green’ then changing the edge color in the selection menu does not change the graph at all. Strangly, if the node color is set to ‘black’ then switching between edge colors works perfectly.

Note that the same effect occurs if you use a Holomap instead of a dynamic map or chose other graph attributes.

If you have any ideas why the bug occurs or how I could solve, it would be a great help.

import numpy as np
import holoviews as hv
hv.extension('bokeh')

# function that creates a graph with two nodes and one connecting edge and sets its edge and node color to the given 
# function parameters
def hv_graph(edge_color, node_color):
    node_indices = np.arange(2, dtype=np.int32)
    source = np.zeros(2, dtype=np.int32)
    target = node_indices
    graph = hv.Graph(((source, target),)).opts(edge_color=edge_color, node_color=node_color)
    return graph

def main():
    # create the dynamic map
    dmap = hv.DynamicMap(hv_graph, kdims=["edge_color", "node_color"])
    dmap = dmap.redim.values(edge_color=["green", "black"], node_color=["green", "black"])
    # save the dynamic map
    hv.save(dmap, 'dmap.html', backend='bokeh')
    return

if __name__ == '__main__':
    main()

I can reproduce that, either with a HoloMap or a DynamicMap. It seems like a bug to me. Could you open an issue?

I had a similar thread regarding DynamicMap and Trimesh and I opened it as an issue. It seems that at times DynamicMap is caching and displaying an older result

Hmm I don’t know to which extent these two issues are related. In this one the interactive visualization in a notebook works well, it’s actually the saving mechanism that seems to be failing there, which is different from the trimesh/dynamicmap issue you link, at least it seems like.

I encourage you anyway to open an issue and post your minimal reproducible example, this helps contributors to track bugs and fix them eventually :slight_smile:

Note that in that particular case, I believe that under the hood it’s Panel that is responsible for saving the Holoviews object as HTML. If you post the issue, post it anyway on the Holoviews issue tracker!

Thank you for the replies!
I just opened an issue under https://github.com/holoviz/holoviews/issues/5102. I’m new here, so if you want me to change or add anything in it, please let me know.

1 Like

Thanks for taking the time, that’s great! I just added a note in the issue.