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

Callback forces reload

Hey guys,

I’m trying to make an app when pushed on the button submit, as seen below, a calculation of max 1-2 minutes is performed and a graph is shown.

However, the page reloads a few seconds after clicking on submit. In Spyder though, I can see that the calculations have finished and an output is generated. Any idea what the problem may be, since I don’t get any errors.

Below is the code for the callback. the id output shows a table of selected file names and result has to show a graph/animation + button. the if-statement checks whether the input is None, which is on startup of the app. Since the callback is fired upon startup.

Thanks in advance!

    [Output('output', 'children'),
     Output('result', 'children')],
    [State('rir_and_speech', 'children')]

def result(n_clicks, value):
    rirs = []
    speeches = []
    for i in value:
    statements= ['angle','speech-file']
    table = html.Table([
            html.Td([statements[j]+str(i+1)+': ', value[i].get('props').get('children')[j].get('props').get('value')]) for j in range(2)
    for i in range(len(value))], className="table_results")
    if rirs == [None] or speeches == [None]:
        return ["Nog Niets"],[]
        n_seq = len(rirs)
        mr = MeetingRoom()
        speech,answers =  mr.conversation_linear(rirs, speeches,  overlap= 0, sample = False)
        srcloc = SourceLocalization(recording_filename='./output/sim_audio.npy', 
                                    # num_angles_theta=360,
                                    # save_path='graphs/two/test/'
        # srcloc.plot_histogram_theta_windowed(hist_type='weighted')
        peaks = srcloc.peak_detection()
        speakers, positions = srcloc.speaker_positions(n_seq, peaks)
        srcloc.post_process(speakers, positions)
        #Make a nx4 array that represent the speakers. if nan -> not spoken, else -> degree of the speaker
        speakers = np.transpose(np.where(srcloc.speakers == False, np.nan, srcloc.speakers)) * srcloc.positions
        animation = AnimationMeetingRoom(speakers)
        fig = animation.fig
        graph_meeting_room = dcc.Graph(id='fig',figure=fig, responsive=True)
        audio_meeting_room = html.Div([html.Button(id="play_mr"),
        result = [graph_meeting_room, audio_meeting_room]
        return table, result