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

How do I fire a callback of my graph using another callback?


I was looking for some way to update my graph when I click in a button but not using Input. My current application updates a graph using the function “update_graph_scatter” (that is a callback for a dropdown box). And I have a button START which calls the function “sendCommand” (that is also a callback). This button starts a server remotely. When I do the sequence START > STOP > again START, my graph gets messy. So I was looking for some way to update it. I though to fire the call back of the graph update from the button function. Like this example ( But it is not working. The graph continues messy.

Actually, I just want to clean the graph when I click on the START button.

     Output(component_id='data', component_property='figure'), 
    [Input(component_id='edgeNodeIds', component_property='value')], 
    events=[Event('graph-update', 'interval')])
def update_graph_scatter(value):
    print(".............. update_graph_scatter function start ..............")

     Output(component_id='button-output', component_property='children'),
    [Input(component_id='button-start', component_property='n_clicks'),
     Input(component_id='button-stop', component_property='n_clicks')],
    [State(component_id='edgeNodeIds', component_property='value')])
def sendCommand(clickStart, clickStop, value):
    print('Button pressed. You\'ve selected: "{}"'.format(value))
    # undecorated(update_graph_scatter)(value)


In your update scatter plot callback, I suppose you have something like:

def update_graph_scatter(value):
    data = list_of_dataframe_of_interesting_numbers

You could try and have a clear step at the beginning of this like:

def update_graph_scatter(value):
    data = [] #or del data to clear the data variable
    data = list_of_dataframe_of_interesting_numbers

Then at each fire of your callback, it will forget all earlier shennanigans. Hope it helps :slightly_smiling_face:.