I'm doing a Get request that includes the data from the dataframe, which I convert to csv.
'/dash/urlToDownload?value={}'.format(df.to_csv(index=False,
sep=',',
encoding='utf-8'))
The route looks as follows;
@app.server.route('/dash/urlToDownload')
def download_csv():
value = flask.request.args.get('value')
# create a dynamic csv or file here using `StringIO`
# (instead of writing to the file system)
strIO = io.StringIO()
strIO.write(value)
writer = csv.writer(strIO, delimiter=',', quotechar='|')
writer.writerow(value)
mem = io.BytesIO()
mem.write(strIO.getvalue().encode('utf-8'))
mem.seek(0)
strIO.close()
return flask.send_file(mem,
mimetype='text/csv',
attachment_filename='downloadFile.csv',
as_attachment=True)
I do get a csv file, but it doesn't recognize new lines and everything is written in the first row.
An example of what the variable value looks like;
version,id,value1,2,3
it seems that there are no characters between value and 1 to indicate a new line.