Separate callbacks for figure and table

master
Dan Howe 6 years ago
parent 28eb278120
commit f282ecc8ad

@ -25,8 +25,7 @@ app.layout = html.Div([
@app.callback(
[Output('storage', 'children'),
Output('div-table', 'children')],
Output('storage', 'children'),
[Input('button', 'n_clicks')],
)
def load_data(n_clicks):
@ -56,17 +55,45 @@ def load_data(n_clicks):
# Round floats
df = df.round(2)
variables = {
'location': '',
'H_sig': 'o',
'H_1%': 'x',
'H_max': '',
'Hm0': '',
'Tp': '',
'Tp1': '',
}
return df.to_json(orient='table')
@app.callback(
Output('graph', 'figure'),
[Input('storage', 'children')],
)
def update_graph(json_data):
if json_data is None:
return {'data': []}
df = pd.read_json(json_data, orient='table')
ts = []
for col in df.columns:
trace = go.Scatter(x=df.index, y=df[col], name=col, opacity=0.8)
ts.append(trace)
layout = {'title': 'basename', 'xaxis': {'rangeslider': {}}}
timeseries = {'data': ts, 'layout': layout}
return timeseries
@app.callback(
Output('div-table', 'children'),
[Input('storage', 'children')],
)
def update_table(json_data):
if json_data is None:
return {'data': []}
df = pd.read_json(json_data, orient='table')
stats = df.describe().T
stats = stats.round(2)
s1 = stats.index.to_series()
s1.name = 'Name'
stats = pd.concat([s1, stats], axis=1)
@ -95,30 +122,7 @@ def load_data(n_clicks):
'maxWidth': '100px',
},
)
return df.to_json(orient='table'), [datatable]
@app.callback(
Output('graph', 'figure'),
[Input('storage', 'children')],
)
def update_graph(json_data):
if json_data is None:
return {'data': []}
df = pd.read_json(json_data, orient='table')
ts = []
for col in df.columns:
trace = go.Scatter(x=df.index, y=df[col], name=col, opacity=0.8)
ts.append(trace)
layout = {'title': 'basename', 'xaxis': {'rangeslider': {}}}
timeseries = {'data': ts, 'layout': layout}
return timeseries
return [datatable]
# @app.callback(Output('datatable-row-ids-container', 'children'), [

Loading…
Cancel
Save