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

Getting errors after add the export datatable function in the datatable

Hi, I want to export the upload the datatable after I edit it. But I get errors when I add the export function in the datatable. Can anyone teach me how to fix the errors or got any other ways to export the datatable?

The error is:
Callback error updating output-data-upload.children
TypeError: Unexpected keyword argument export_format Allowed arguments: active_cell, columns, css, data, data_previous, data_timestamp, derived_filter_query_structure, derived_viewport_data, derived_viewport_indices, derived_viewport_row_ids, derived_viewport_selected_row_ids, derived_viewport_selected_rows, derived_virtual_data, derived_virtual_indices, derived_virtual_row_ids, derived_virtual_selected_row_ids, derived_virtual_selected_rows, dropdown, dropdown_conditional, dropdown_data, editable, end_cell, filter_action, filter_query, fixed_columns, fixed_rows, id, is_focused, locale_format, merge_duplicate_headers, page_action, page_current, page_size, row_deletable, row_selectable, selected_cells, selected_row_ids, selected_rows, sort_action, sort_as_null, sort_by, sort_mode, start_cell, style_as_list_view, style_cell, style_cell_conditional, style_data, style_data_conditional, style_filter, style_filter_conditional, style_header, style_header_conditional, style_table, tooltip, tooltip_conditional, tooltip_data, tooltip_delay, tooltip_duration, virtualization

Below is my code:

import base64
import datetime
import io

import dash
from dash.dependencies import Input, Output, State
import dash_core_components as dcc
import dash_html_components as html
import dash_table
import pandas as pd


external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']

app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
app.config['suppress_callback_exceptions']=True
app.layout = html.Div([
    dcc.Upload(
        id='datatable-upload',
        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'
        },
    ),
    html.Div(id='output-data-upload'),
])


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('output-data-upload', 'children'),
               [Input('datatable-upload', 'contents')],
               [State('datatable-upload', 'filename')])
def update_output(contents, filename):
    if contents is None:
        return []
    df = parse_contents(contents, filename)
    return html.Div([
        dash_table.DataTable(
            id='table',
            style_data={
                'whiteSpace': 'normal',
                'height': 'auto'
            },
            style_table={'overflowX': 'scroll',
                         'maxHeight': '300',
                         'overflowY': 'scroll'},
            style_cell={
                'minWidth': '150px', 'maxWidth': '180px',
                'whiteSpace': 'normal',
                'textAlign': 'left'
            },
            style_header={
                'fontWeight': 'bold',
            },
            fixed_rows={'headers': True, 'data': 0},
            columns=[{"name": i, "id": i, 'deletable': True, 'renamable': True} for i in df.columns],
            data=df.to_dict("records"),
            row_deletable=True,
            filter_action="native",
            sort_action="native",
            sort_mode='multi',
            editable=True,
            export_format='csv',
            export_headers='display',
            merge_duplicate_headers=True,
        )
    ])



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

What version of Dash et al are you running? I am running the latest (see below) and your code does not fail.

dash                      1.7.0     
dash-bootstrap-components 0.7.2     
dash-core-components      1.6.0     
dash-daq                  0.3.1     
dash-html-components      1.0.2     
dash-renderer             1.2.2     
dash-table                4.5.1 
2 Likes

@flyingcujo, thanks for the help, the code work now after I change the version of Dash et al as you show.

1 Like