I am am creating a web app with Python and Flask. My python code outputs a pandas dataframe, which I would like the user to download by the click of a button. More specifically, I want the user to click the download button and I want the csv file to be displayed as a download on the bottom download bar in Google Chrome (Something like this picture.).
Here's what I did so far:
HTML button:
 <a class="btn btn-primary" onclick="csvDownload()" href=""  type="button">Download</a>
Which leads to this JavaScript function:
 function csvDownload() {
        location.replace('/download')
    }
In Flask, I process it like so:
@app.route('/download')
def download():
   backend.final_data.to_csv()
Here, backend.final_data is my data frame coming from another python file called backend.