【发布时间】:2019-10-27 03:59:34
【问题描述】:
我想将带有复数的 csv 文件上传到散景网络应用程序中。 DuCorey 的解决方案非常适用于整数和浮点数,请参阅:Upload a CSV file and read it in Bokeh Web app 但是,当我在 models.py 中将 values_type 从 Int 更改为 Complex 并将复数插入 csv 文件时,它不再起作用。我不想像 DuCorey 那样绘制导入的数组(并且在他的示例中不起作用)。只需导入值和 f.e.打印出来。
我更改了以下三个文件:
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 文件
x,y
1,2
3,3
3,5+1j
10,25
和 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)
我收到以下错误消息: DeserializationError('Complex 预期 Complex,得到 5+1j').
感谢所有建议!
【问题讨论】:
标签: javascript python file-upload bokeh