2

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.

Dapu Zhang
  • 31
  • 1
  • 2
  • This kind of question will be voted down and closed as being not suitable for Stack Overflow. I'd suggest you come to the Bokeh Project Discourse for more general Q&A type support: https://discourse.bokeh.org – bigreddot Aug 07 '19 at 00:50

1 Answers1

2

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.

Joris
  • 1,158
  • 1
  • 16
  • 25