Black Lives Matter. Please consider donating to Black Girls Code today.

Callback: input values are kept from a callback to another

Hello community,

I’m trying to create a callback that can update a Dash Cytoscape component. It has several inputs and they get in each other’s way…

My callback looks a bit like this:

    [Output('cytoGraph', 'elements'), 
     Output('cytoGraph', 'stylesheet')],
    [Input('dropdownlist_climbs', 'value'),
     Input('dropdownlist_routes', 'value'),
     Input('dropdownlist_places', 'value'),
     Input('dropdownlist_participants', 'value'),
     Input('cytoGraph', 'tapNodeData'),
     Input('map', 'hoverData') ])
def update_graph(climbs, routes, places, participants, selected_node, hoverData):

    if selected_node:
        elements, stylesheet = rdf_to_cytoscape(rdf.graphDB, URIRef(str(selected_node["URI"])))

    if hoverData:
        elements, stylesheet = rdf_to_cytoscape(rdf.graphDB, URIRef(hoverData['points'][0]['customdata'][0]))

    return (elements, stylesheet)

I’m redrawing the Cytoscape when changing values in drop down lists, or by hovering over a map or by clicking nodes on the Cytoscape itself. All individually work fine but once I use one input, that input is remembered at the next callback and I cannot use other inputs.

Say for example I hover on the map, my nodes are updated (I re-create Elements and Stylesheets, i.e. the outputs). Or if I click on a node, the graph is updated and centered and the node I selected. I can’t figure to do both: hovering on the map and (in a second callback) select a node. The property HoverData is still in memory so both IF statements are read. I was hoping that the callback would start from scratch, i.e. only what the user just did is passed as not None. Any clue how I could make this callback?

In case you need, my code is over here:

Appreciate your help!

thanks !

Hi @ndupuis, you can use dash.callback_context to know which input triggered the callback, see the FAQ page for more details (question : How do I determine which Input has changed).

Worked perfectly, simplified my code a lot too. Great. Merci Emmanuelle!

1 Like