Export the full table in pagination - Dash Tables

0

I am using pagination to show my data in a dash table, but when I click on export button it exports just the current view or the number of rows being shown.

from dash import Dash, dash_table
from dash.dependencies import Input, Output
import pandas as pd


df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/gapminder2007.csv')

df[' index'] = range(1, len(df) + 1)

app = Dash(__name__)

PAGE_SIZE = 5

app.layout = dash_table.DataTable(
    id='datatable-paging',
    columns=[
        {"name": i, "id": i} for i in sorted(df.columns)
    ],
    page_current=0,
    page_size=PAGE_SIZE,
    page_action='custom',
    export_format='xlsx',
    export_headers='display',
    merge_duplicate_headers=True
)


@app.callback(
    Output('datatable-paging', 'data'),
    Input('datatable-paging', "page_current"),
    Input('datatable-paging', "page_size"))
def update_table(page_current,page_size):
    return df.iloc[
        page_current*page_size:(page_current+ 1)*page_size
    ].to_dict('records')


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

Please help me in exporting the full table by creating a new call back or editing in the current code.

Hi @rohitkrsingh
Welcome to the Dash Community :tada:

See the answer to your question in another post on the Forum. (export the dataframe directly to xlsx and not use the datatable)