I want to upload a .txt file with two column datas using the bokeh FileInput widget and then plot the data interactively. Can someone provide me a minimal example?
Thanks a lot.
I want to upload a .txt file with two column datas using the bokeh FileInput widget and then plot the data interactively. Can someone provide me a minimal example?
Thanks a lot.
There is an example on importing files via the server directory structure and papaparse here: Upload a CSV file and read it in Bokeh Web app
This was made a long time ago, before the FileInput widget was officially included with the Bokeh 1.3.0 distribution. Now it should work with this new widget however i cannot find the documentation on how to add a server callback to it.
After testing i come to this use of the new FileInput widget:
from bokeh.io import curdoc
from bokeh.models.widgets import FileInput
def upload_fit_data(attr, old, new):
print("fit data upload succeeded")
print(file_input.value)
file_input = FileInput(accept=".csv,.json,.txt")
file_input.on_change('value', upload_fit_data)
doc=curdoc()
doc.add_root(file_input)
This will give you the file data as a base64 encoded string (file_input.data). I leave it up to you to convert the base64 string to what you want and plot the data.