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

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

Hi,

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 (https://community.plotly.com/t/programmatically-firing-a-callback/7988). But it is not working. The graph continues messy.

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

@app.callback(
     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 ..............")

@app.callback(
     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))
    # THIS DOES NOT WORK PROPERLY
    # undecorated(update_graph_scatter)(value)

Thanks,
Felipe

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

def update_graph_scatter(value):
    data = list_of_dataframe_of_interesting_numbers
    plot(data)

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
    plot(data)

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