✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
⚡️ Concerned about the grid? Kyle Baranko teaches how to predicting peak loads using XGBoost. Register for the August webinar!

Having trouble with the upload component

I took the upload example from the dash documentations and wanted to expand it to accomodate the upload of .ifc files. I manage to read the file but as soon as I try to do something with the file using the ifc module the server crashes with the error message:

Callback failed: the server did not respond.

(This error originated from the built-in JavaScript code that runs Dash apps. Click to see the full stack trace or open your browser’s console.)

Where exactly do I have to click to see the full stack trace? I open the beowsers console and there is nothing there…

Here is the code

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)

If I take the “project” variable out everything works… What am I doing wrong?

Anybody? Can someone tell me how to find this error that originates from the built-in JavaScript node?