Show error message when file cannot be loaded

master
Dan Howe 5 years ago
parent 6cbb33842e
commit a6db6edbfd

@ -117,25 +117,17 @@ def parse_contents(contents, filename):
Input('upload-data', 'contents'), Input('upload-data', 'contents'),
Input('upload-data', 'filename'), Input('upload-data', 'filename'),
]) ])
def csv_to_json(contents, name): def csv_to_json(contents, filename):
if contents is not None: if contents is not None:
return parse_contents(contents, name) try:
json_data = parse_contents(contents, filename)
except:
json_data = json.dumps({'error': filename})
return json_data
@app.callback(Output('output-data-upload', 'children'),
[Input('json-storage', 'children')])
def read_json_data(json_data):
if json_data is None:
elements = html.Div([
dcc.Graph(),
html.Div([
html.Div([dcc.Graph()], className='six columns'),
]),
html.Div()
])
return elements
def update_objects(json_data):
info = json.loads(json_data)['info'] info = json.loads(json_data)['info']
df = pd.read_json(json.loads(json_data)['timeseries'], orient='table') df = pd.read_json(json.loads(json_data)['timeseries'], orient='table')
ts = [] ts = []
@ -229,6 +221,38 @@ def read_json_data(json_data):
return elements return elements
@app.callback(Output('output-data-upload', 'children'),
[Input('json-storage', 'children')])
def read_json_data(json_data):
if json_data is None:
elements = html.Div([
dcc.Graph(),
html.Div([
html.Div([dcc.Graph()], className='six columns'),
]),
html.Div()
])
elif json.loads(json_data)['error']:
filename = json.loads(json_data)['error']
elements = html.Div([
dcc.Graph(figure={
'layout': {
'title': 'Error reading {}'.format(filename)
}
}),
html.Div([
html.Div([dcc.Graph()], className='six columns'),
]),
html.Div()
])
else:
elements = update_objects(json_data)
return elements
def main(): def main():
port = 8050 port = 8050
wb.open('http://localhost:{}'.format(port)) wb.open('http://localhost:{}'.format(port))

Loading…
Cancel
Save