python - Plotly Dash 上传组件
问题描述
我从破折号文档中获取了上传示例,并希望对其进行扩展以适应 .ifc 文件的上传(AEC 行业的 3D 模型)。我设法读取了文件,但是一旦我尝试使用 ifc python 包对文件执行某些操作,服务器就会崩溃并显示错误消息:
回调失败:服务器没有响应。(此错误源于运行 Dash 应用程序的内置 JavaScript 代码。单击以查看完整的堆栈跟踪或打开浏览器的控制台。)
我必须在哪里单击才能查看完整的堆栈跟踪?我打开 beowsers 控制台,里面什么都没有……</p>
这是代码
import base64
import datetime
import io
import dash
from dash.dependencies import Input, Output, State
import dash_core_components as dcc
import dash_html_components as html
import dash_table
import ifcopenshell as ifc
from Functions import *
import pandas as pd
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
app = dash.Dash(__name__, external_stylesheets=external_stylesheets, prevent_initial_callbacks=True)
app.layout = html.Div([
dcc.Upload(
id='upload-data',
children=html.Div([
'Drag and Drop or ',
html.A('Select Files')
]),
style={
'width': '100%',
'height': '60px',
'lineHeight': '60px',
'borderWidth': '1px',
'borderStyle': 'dashed',
'borderRadius': '5px',
'textAlign': 'center',
'margin': '10px'
},
# Allow multiple files to be uploaded
multiple=True
),
html.Div(id='output-data-upload'),
])
def parse_contents(contents, filename, date):
content_type, content_string = contents.split(',')
decoded = base64.b64decode(content_string)
try:
if 'csv' in filename:
message = "YAAAAAAAY"
# Assume that the user uploaded a CSV file
dfa = pd.read_csv(
io.StringIO(decoded.decode('utf-8')))
elif 'xls' in filename:
message = "YAAAAAAAY"
# Assume that the user uploaded an excel file
dfa = pd.read_excel(io.BytesIO(decoded))
elif '.Ifc'.lower() in filename.lower():
ifc_file = ifc.file.from_string(contents)
#test = ifc_file.schema
#instances = ifc_file.by_type("IfcBuildingElement")
project = ifc_file.by_type("IfcProject")[0].Name
except Exception as e:
print(e)
return html.Div([
'There was an error processing this file.'
])
return html.Div([
html.H5(str(type(ifc_file)))
])
@app.callback(Output('output-data-upload', 'children'),
Input('upload-data', 'contents'),
State('upload-data', 'filename'),
State('upload-data', 'last_modified'),prevent_initial_call=True)
def update_output(list_of_contents, list_of_names, list_of_dates):
if list_of_contents is not None:
children = [
parse_contents(c, n, d) for c, n, d in
zip(list_of_contents, list_of_names, list_of_dates)]
return children
if __name__ == '__main__':
app.run_server(debug=True)
如果我把“项目”变量去掉,一切正常……我做错了什么?
解决方案
推荐阅读
- html - 样式化 HTML 表格元素,使其具有受 colspan 和 rowspan 影响的较粗边框部分
- c# - C# 中的 Excel 条件格式规则 - 检查不同列中的单元格是否具有特定值
- sql-server - 在已排序的列上合并联接而不是哈希联接
- python - 如何使用 Scrapy 抓取下一页
- java - 何时关闭 DL4J INDArrays
- ios - Xamarin.Forms 应用程序在调试中工作,但在 ios 上发布时崩溃
- javascript - Widget iOS 14 使用 swift ui 创建带有 react native 的 ui
- python - 需要在 python pandas 中填充下一个空单元格
- audio - Gstreamer 复制 2 声道音频
- javascript - 如何在不使用 id 或类的情况下选择特定元素