Show fig while updating it

hello, i have a callback that returns a fig. the call back draws a neural network, and as you might have guessed, there are lots of loops involved. the figure is returned after the last loop. but i would like to show the figure after each loop. i tried but that just opens a new tab. here is my code, please help.



def get_result(n_clicks,children):
    hidden_layers  = [x['props'].get('value') for x in children if type(x['props'].get('value')) == int and x['props'].get('value')!=0]  
    fig['layout']['shapes'] = []  # clear shapes (circles)
    fig['data'] = []  # clear connections
    horizontal_distance_between_layers = 0
    if children:

        for layer_number,layer in enumerate(hidden_layers):
            center_layer_vertically =  (max(hidden_layers) - layer) / 2
            connect_to_previous_layer = True if not_first_layer(layer_number) else False   
            horizontal_distance_between_layers +=5
        return fig

    fig.update_layout(width=800, height=800)
    return fig

you can put your for-loop outside the callback.

i am really new to dash, can you please elaborate ? an example would be nice.

thanks in advance