Populate existing data table with CSV file upload

I’m following the tutorial on https://dash.plot.ly/dash-core-components/upload and can’t quite figure out how to upload a CSV file into columns IDs I have made already in the program. Even when df.to_dict(‘records’) seemingly prints out the right values with the right column titles, it still doesn’t show up in the datatable.

do the columns IDs defined in your app match exactly (case, whitespaces…) the names of columns in your CSV file? Could you please share your code and your CSV file (or one CSV file reproducing the issue)?

The column names were the problem, thanks! I was also wondering if it is possible to export different columns to different tables. This is what I currently have. I would like to implement a way to split up the df.to_dict(‘records’) to different data for different tables.

def parse_contents(contents, filename):
content_type, content_string = contents.split(’,’)
decoded = base64.b64decode(content_string)
if ‘csv’ in filename:
# Assume that the user uploaded a CSV file
return pd.read_csv(
io.StringIO(decoded.decode(‘utf-8’)))
elif ‘xls’ in filename:
# Assume that the user uploaded an excel file
return pd.read_excel(io.BytesIO(decoded))

@app.callback(Output(‘battery-charging-table’, ‘data’),
[Input(‘battery-upload’, ‘contents’), Input(‘battery-charging-table’,‘columns’)],
[State(‘battery-upload’, ‘filename’), State(‘battery-charging-table’, ‘data’)])
def update_output(contents, cols, filename, rows):
if contents is None:
return [{}]
df = parse_contents(contents, filename)
print(df.to_dict(‘records’))
return df.to_dict(‘records’)

three reasons why you should buy plotly pro: support open source, get great support, host your plots and dashboards online