Updating data in dash_table

Hi,

I was wondering what format is needed to update the data in a dash table.

For example

html.Div(
    dash_table.DataTable(
        id='file-table',
        columns=[{"name": p, "id": p} for p in params],
        style_cell={'textAlign': 'left'},
    )
)

One of the columns is Filename, and after a callback from uploading files I want to update the values belonging to column Filename.
i’m doing something like this. Where df is a dataFrame that includes the filenames.

@app.callback(Output("file-table", "data"),
              [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):
    return df.fileName.unique()

It does create the x amount of rows, but they are empty.

You need to include some kind of updating of df in your callback.

To me, it looks like df will be defined as you initiate your app and from there df will not change.
You need to include your declaration of df inside your callback as well.

I found the right way to return the data structure.

data = [{'Filename': f} for f in df.fileName.unique()]
return data
1 Like