Black Lives Matter. Please consider donating to Black Girls Code today.

Download a pdf or image

This must be very elementary, but I have been really struggling with it:
I want the user to be able to download a file named “readMe.pdf”.
This file is in the same folder as the Python code (shown below).
When the user clicks on the link, it downloads an empty file (2kb), and when opening the file, shows an error message (Failed to load the document).

import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
app = dash.Dash(__name__)
app.layout = html.Div(
    [
        html.H1('Title'),
        html.A('Download readMe.pdf', download='readMe.pdf', href='/readMe.pdf')
    ])
if __name__ == '__main__':
    app.run_server(debug=True)
1 Like

Put the pdf in the assets folder, change the href to /assets/readMe.pdf.

2 Likes

Thanks a lot. It worked.