Downloads a file already saved on the server's disk (e.g., a PDF or image). Raw Binary Useful for dynamically generated images or zip files. dict(content=...) Text Strings
Dash provides specialized helper functions to format data for the dcc.Download component: Helper Function Description Pandas DataFrames Sends a DataFrame as a CSV or Excel file. dcc.send_file Existing Files
: For very large files (e.g., >100MB), consider using a dedicated Flask route with flask.send_from_directory instead of the Dash component to avoid memory bottlenecks within the Dash callback. Download | Dash for Python Documentation | Plotly python dash dcc download
from dash import Dash, dcc, html, Input, Output, callback import pandas as pd app = Dash(__name__) app.layout = html.Div([ html.Button("Download CSV", id="btn-download"), dcc.Download(id="download-component") ]) @callback( Output("download-component", "data"), Input("btn-download", "n_clicks"), prevent_initial_call=True ) def generate_file(n_clicks): # Example DataFrame df = pd.DataFrame("Col1": [1, 2], "Col2": ["A", "B"]) return dcc.send_data_frame(df.to_csv, "my_data.csv", index=False) if __name__ == "__main__": app.run(debug=True) Use code with caution. Supported Helper Functions
: The dcc.Download component does not render any visual elements; it simply manages the browser's download stream. Downloads a file already saved on the server's disk (e
To use dcc.Download , you typically pair it with a trigger, such as an html.Button .
The dcc.Download component is the standard way to allow users to save files—such as —directly from a Plotly Dash application. This component is invisible in your app's layout but triggers a browser download dialog whenever its data property is updated via a callback. Core Implementation To use dcc
: Always use prevent_initial_call=True in your download callback. Without this, the browser may attempt to trigger a download as soon as the page loads.
Downloads a file already saved on the server's disk (e.g., a PDF or image). Raw Binary Useful for dynamically generated images or zip files. dict(content=...) Text Strings
Dash provides specialized helper functions to format data for the dcc.Download component: Helper Function Description Pandas DataFrames Sends a DataFrame as a CSV or Excel file. dcc.send_file Existing Files
: For very large files (e.g., >100MB), consider using a dedicated Flask route with flask.send_from_directory instead of the Dash component to avoid memory bottlenecks within the Dash callback. Download | Dash for Python Documentation | Plotly
from dash import Dash, dcc, html, Input, Output, callback import pandas as pd app = Dash(__name__) app.layout = html.Div([ html.Button("Download CSV", id="btn-download"), dcc.Download(id="download-component") ]) @callback( Output("download-component", "data"), Input("btn-download", "n_clicks"), prevent_initial_call=True ) def generate_file(n_clicks): # Example DataFrame df = pd.DataFrame("Col1": [1, 2], "Col2": ["A", "B"]) return dcc.send_data_frame(df.to_csv, "my_data.csv", index=False) if __name__ == "__main__": app.run(debug=True) Use code with caution. Supported Helper Functions
: The dcc.Download component does not render any visual elements; it simply manages the browser's download stream.
To use dcc.Download , you typically pair it with a trigger, such as an html.Button .
The dcc.Download component is the standard way to allow users to save files—such as —directly from a Plotly Dash application. This component is invisible in your app's layout but triggers a browser download dialog whenever its data property is updated via a callback. Core Implementation
: Always use prevent_initial_call=True in your download callback. Without this, the browser may attempt to trigger a download as soon as the page loads.