Assign Custom Name to the csv file in dash datatable export

Hello Everyone,
Can someone tell me how can one assign custom name to the exporting table in dash datatable.

Thanks in advance.

Hi @Lucifer what exactly are you referring to? Do you have an example of this?

Hello Aimped,
Lets take this example into consideration :

import dash
import dash_table
import pandas as pd

# Sample data
data = {
    'Name': ['John', 'Alice', 'Bob', 'Mary'],
    'Age': [25, 30, 35, 28],
    'Country': ['USA', 'Canada', 'USA', 'Canada']
}

df = pd.DataFrame(data)

# Create a Dash application
app = dash.Dash(__name__)

# Define the layout
app.layout = dash_table.DataTable(
    id='table',
    columns=[{"name": i, "id": i} for i in df.columns],
    data=df.to_dict('records'),
    export_format="csv"
)

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

now this is the page we get :

now , when i click on the export button , it exports default by the name of ‘Data’.

My query is to provide a different name to the file while exporting . Something like ‘UserData.csv’ or something else by default.

Hi @Lucifer, is the DataTable editable?

If not, you could just export the DataFrame. This example writes a DataFrame into a json file with a static name. Instead of using df.to_json() you can use df.to_csv() and assign your variable value as name of the file.