Allow users to dowload an Excel in a click

I just spent some time strugelling to get my exel file exportation working. I figured I would share it here as it was not so obvious how to implement it for the beginner I am. I implemented what @chriddyp suggested with send_data_frame from dash_extensions https://pypi.org/project/dash-extensions/ :

import dash
import pandas as pd
from dash_extensions import Download
from dash_extensions.snippets import send_data_frame
import dash_html_components as html

app = dash.Dash(__name__)

app.layout = html.Div(
    children=[
         html.Button("Download Excel File", id='download-results-button'),
         Download(id='download')])

@app.callback(Output('download', 'data'),
             [Input('download-results-button', 'n_clicks')])
def download_data(n_clicks):
    d = {"col1": [1, 2], "col2": [3, 4]}
    df = pd.DataFrame(data=d)
    return send_data_frame(df.to_excel, filename='data.xlsx')

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

I hope it can help some other lost souls get to something running faster!