I am using flask routes to download a text file within my dash app. This works locally in my test environment, however when I deploy my app on rsconnect, the download link does not work (route does not work) and I get 404 error. Any idea how to overcome this issue?
@app.callback(
Output('download-link-button', 'href'),
Input(component_id='dropdown',component_property='value')
)
def update_link(value):
csv_file = df[value].to_csv(columns=['v1','v2']).replace('\n', '<br>').replace('&', '<amp;>')
return f'/dash/urlToDownload?value={csv_file}'
@server.route('/dash/urlToDownload')
def download_csv():
value = flask.request.args.get('value')
strIO = io.StringIO()
strIO.write(value.replace("<br>", '\n')
.replace('<amp;>', '&')
)
mem = io.BytesIO()
mem.write(strIO.getvalue().encode("utf-8"))
mem.seek(0)
strIO.close()
return flask.send_file(mem,
attachment_filename='Info.csv',
as_attachment=True)