I’m trying to modify an existing program I have such that it allows the user to select a file, which some python code then processes and some nice plots result. However, I’m really stuck on getting the input from the FileInput reader into a dataframe. My inputs are in relatively standardized xls and xlsx files, but I can’t figure out how I can put them in a dataframe as pd.read_excel expects a link to the file.
Here is the simple code I’m using to try and test my function, I’m sure I’m missing something simple but I’ve spent a fair bit of time trying to figure this out an am not making much headway.
from bokeh.io import curdoc
from bokeh.models.widgets import FileInput
from pybase64 import b64decode
import pandas as pd
def upload_fit_data(attr, old, new):
print("fit data upload succeeded")
print(file_input.value)
print(type(new))
decoded = b64decode(new)
#print("Decoded: ", decoded)
xls = pd.read_excel(decoded)
print(xls)
#f = open(decoded, "r")
#contents = f.read()
#print(contents)
file_input = FileInput(accept=".csv,.json,.txt,.pdf,.xls")
file_input.on_change('value', upload_fit_data)
doc=curdoc()
doc.add_root(file_input)


