
Hi,
I am having issues trying to figure out how to download a file like done in this example:
So the user uploads a file, which is very messy, the code cleans it and should output a file downloaded to downloads folder as the example from the bokeh gallery.
Anyone done something similar with a Pandas Dataframe that could show me an example?
from bokeh.io import curdoc
from bokeh.models.widgets import FileInput
import pandas as pd
from bokeh.models import CustomJS
from pybase64 import b64decode
import io
from flask import send_file, session, make_response, Response
from os.path import dirname, join
def upload_csv_file(attr, old, new):
print('uploading csv file...')
file = io.BytesIO(b64decode(new))
wttdata = pd.read_csv(file, sep = ',', header = 0)
headerData = wttdata[:4]
wttdata = wttdata.replace('x', '', regex=True)
wttdata = wttdata.groupby(['Date time'], as_index=False).agg('first')#.reset_index()
result = pd.concat([headerData, wttdata], axis=0)
print(result)
#resp = make_response(result.to_csv('test_file.csv', index = None, header=True))
#resp.headers["Content-Disposition"] = "attachment; filename=export.csv"
#resp.headers["Content-Type"] = "text/csv"
#result.to_csv('test_file.csv', index = None, header=True)
return Response(
result.to_csv('test_file.csv', index = None, header=True),
mimetype="text/csv",
headers={"Content-disposition":
"attachment; filename=filename.csv"})
def fileConverter(doc):
inputFile = FileInput(accept=".csv,.json,.txt")
inputFile.on_change('value', upload_csv_file)
doc.add_root(inputFile)


