Hello everyone!
I am relatively new to Bokeh but starting to get around a bit better.
I have a relatively long file that first ask to updload some csv files and then the data in the files is filtered and plotted in 4 graphs.
I would like to give the the filename of the csv to the file when uploaded with the FileInput widget. But for some reason, I can only retrieve the name after I click on the button “upload data” and not directly in the callback function of the FileInput widget.
Here is the simplified code with only one button.
series = []
def upload_data1(attr, old, new): # there are several fileinput widgets
print('file uploaded successfully...')
decoded = b64decode(new)
f = io.BytesIO(decoded)
data1 = pd.read_csv(f, sep=';')
data1 = data1.loc[:, ~data1.columns.str.contains('^Unnamed')]
series.append(data1)
print('file_input1.filename 1 :', file_input1.filename)
def load_data():
print('file_input1.filename 2:', file_input1.filename)
columns = sorted(series[0].columns) # every set of data uploaded has the same columns
plotting(series, columns) # function that creates new widgets and plots graphs with all the data in series
# File input
file_input1 = FileInput(accept=".csv", width=250)
file_input1.on_change('value', upload_data1)
bt = Button(label="Load data", width=150)
bt.on_click(load_data)
data_set = row([file_input1, bt])
curdoc().add_root(data_set)
show(data_set)
def plotting(series, columns):
pass
I then call my code with bokeh serve --websocket-max-message-size 100000000 github.py
As you can see, I can only access the filename in the function load_data:
Is there a way to get in the callback function ?
Thank you for your help