I want to upload a csv-file with complex numbers into a bokeh web app. The solution of DuCorey works perfectly for integer and floats, see: Upload a CSV file and read it in Bokeh Web app But when I change the values_type from Int to Complex in models.py and insert a complex number into the csv-file, it doesn't work anymore. I do not want to plot the imported array as DuCorey did (and it would not work in his example). Just import the values and f.e. print them.
I changed the following three files:
models.py
from bokeh.core.properties import List, String, Dict, Int, Complex, Float
from bokeh.models import LayoutDOM
class FileInput(LayoutDOM):
__implementation__ = 'static/js/extensions_file_input.coffee'
__javascript__ = './input_widget/static/js/papaparse.js'
value = String(help="""
Selected input file.
""")
file_name = String(help="""
Name of the input file.
""")
accept = String(help="""
Character string of accepted file types for the input. This should be
written like normal html.
""")
data = List(Dict(keys_type=String, values_type=Complex))
csv-file
x,y
1,2
3,3
3,5+1j
10,25
and main.py
from bokeh.core.properties import List, String, Dict, Int
from bokeh.models import LayoutDOM
from bokeh.layouts import column
from bokeh.models import Button, ColumnDataSource
from bokeh.io import curdoc
from bokeh.plotting import Figure
import pandas as pd
from models import FileInput
button_input = FileInput(id="fileSelect",
accept=".csv")
def change_plot_data(attr, old, new):
new_df = pd.DataFrame(new)
print(new_df)
button_input.on_change('data', change_plot_data)
layout = column(button_input)
curdoc().add_root(layout)
I get the following error message: DeserializationError('Complex expected Complex, got 5+1j').
Thanks for all advices!