Dash table updates empty rows

Hi everyone,

I made this small dashboard and I wanted to test a dynamically updating “results table” at the end of the page.
I created these test lines to see how i can update it, but it seems to not update correctly. It shows two additional rows in the output table but it doesnt show any values. When printing out the df the correct values are shown.

It would be great if you can help me.

Cheers,
Mjst


upload = html.Div([
    dcc.Upload(
        id='upload-data',
        children=html.Div([
            'Drag and Drop or ',
            html.A('Select Files')
        ]),
        style={
            'width': '100%',
            'height': '60px',
            'lineHeight': '60px',
            'borderWidth': '1px',
            'borderStyle': 'dashed',
            'borderRadius': '5px',
            'textAlign': 'center',
            'margin': '10px'
        },
        # Allow multiple files to be uploaded
        multiple=True
    ),
    html.Div(id='output-data-upload'),
])


def parse_contents(contents, filename, date):
    content_type, content_string = contents.split(',')

    decoded = base64.b64decode(content_string)
    try:
        if 'csv' in filename:
            # Assume that the user uploaded a CSV file
            df = pd.read_csv(
                io.StringIO(decoded.decode('utf-8')))
        elif 'xls' in filename:
            # Assume that the user uploaded an excel file
            df = pd.read_excel(io.BytesIO(decoded))
    except Exception as e:
        print(e)
        return html.Div([
            'Es ist ein Fehler bei dem Hochladen ihrer Datei aufgetreten. Bitten überprüfen Sie ob die Datei im Richtigen Format ist. Wenn dass der Fall ist kontaktieren Sie bitte den Support.'
        ])

    return html.Div([
        html.H5(filename),
        html.H6(datetime.datetime.fromtimestamp(date)),

        dash_table.DataTable(
            id = 'produkt_daten',
            data=df.to_dict('records'),
            columns=[{'name': i, 'id': i} for i in df.columns]
        ),

        html.Hr(),  # horizontal line
])

# marge & button zum berechnen

button_berechnen = html.Div([
    dbc.Row([
        dcc.Input(
            id="input_marge",
            placeholder= 'marge in 1XX% i.e. 1.4'),
        html.Button('Berechnen', id ='submit-marge', n_clicks = 0),
    ]),
])
#output tabelle
output_table = html.Div([
    dash_table.DataTable(
    id = 'output_table',
    columns = [ {'name' : 'Index', 'id': "index"},
                {'name' : 'Produkt', 'id':"produkt"},
                {'name' : 'Ebay', 'id':"ebay"},
                {'name' : 'Amazon', 'id':"amazon"},
                {'name' : 'Real', 'id':"real"},
                {'name' : 'Webshop', 'id':"webshop"}],
    style_cell = {
        'backgroundColor': 'rgb(50,50,50)',
        'color': 'white'

    },
    editable = True
    )
])

#download button der tabelle



# layout
app.layout = dbc.Container([
    info_card,
    upload,
    button_berechnen,
    output_table,

])

#callbacks

#updating upload table
@app.callback(Output('output-data-upload', 'children'),
              Input('upload-data', 'contents'),
              State('upload-data', 'filename'),
              State('upload-data', 'last_modified'))
def update_output(list_of_contents, list_of_names, list_of_dates):
    if list_of_contents is not None:
        children = [
            parse_contents(c, n, d) for c, n, d in
            zip(list_of_contents, list_of_names, list_of_dates)]
        return children

@app.callback(Output('output_table', 'data'),
            Input('submit-marge', 'n_clicks'),
            #Input('produkt_daten', 'data'),
            State('input_marge', 'value'))
#berechnen des output tables
def rows_berechnen(n_clicks, marge):
    if n_clicks >0 :
        df_preise = pd.DataFrame(columns = {'Produkt', 'Ebay', 'Amazon', 'Real', 'Webshop'})
        test = {'Produkt' : 'marge', 'Ebay': marge, 'Amazon': marge, 'Real': marge, 'Webshop': marge}
        test2 = {'Produkt' : 'marge', 'Ebay': marge, 'Amazon': marge, 'Real': marge, 'Webshop': marge}
        df_preise = df_preise.append(test, ignore_index=True)
        df_preise = df_preise.append(test2, ignore_index=True)

        print(df_preise)
        df = df_preise.to_dict(orient ='records')
        return df
    raise PreventUpdate



if __name__ == '__main__':
    app.run_server(debug=True)