Dash Cytoscape callback not working when the same node is clicked twice in a row

Hello everyone, right now I am working on creating an interface that requires users to be able to interact with the nodes in a cytoscape in a way similar to buttons.

As the title describes, I am encountering an issue where the callback won’t trigger if you try clicking on the last-clicked node. For example let’s say I have 3 nodes: n1, n2, and n3.

If I click on n1, it will execute the behavior that is expected to occur for clicking on a node. But if I click it again directly after, it won’t work. However, if I click on n2 the behavior for n2 will work, but clicking on n2 again will make it not work. The only way to “refresh” a node is to click on another node, which is not the behavior I want.

I am not sure if this is a problem with my cytoscape or callback. If anyone can give some insight it would greatly be appreciated.

Here is the callback in question:


@callback(Output('cytoscape-tapNodeData-output', 'children'),
              Input('cytoscape-flowchart', 'tapNodeData'))
def displayTapNodeData(data):
    if data:
        print( "You recently clicked the node: " + data['label'])
        return data['label']

I just figured out what the issue was, I wasn’t clearing the value of tapNodeData after the callback was executed.

This is my fix:

@callback([Output('cytoscape-tapNodeData-output', 'children'),
Output('cytoscape-flowchart', 'tapNodeData')],
Input('cytoscape-flowchart', 'tapNodeData'))
def displayTapNodeData(data):
    if data:
        print( "You recently clicked the node: " + data['label'])
        return data['label'], None