The following gives only an Error loading dependencies
message in the browser window. I don’t get any error messages elsewhere, and I’m not sure what is causing the error.
If I comment out lines 135 - 149 and uncomment lines 121 - 132 then the app runs correctly.
import dash
import dash_table
from dash.dependencies import Input, Output
import dash_core_components as dcc
import dash_html_components as html
equals = ' = '
plus = ' + '
end = ''
apples={
'name': 'apples',
'val': '10',
'rel': '2'
}
bananas={
'name': 'bananas',
'val': '10',
'rel': '2'
}
pears={
'name': 'pears',
'val': '10',
'rel': '2'
}
oranges={
'name': 'oranges',
'val': '10',
'rel': '2'
}
kiwi={
'name': 'kiwi',
'val': '10',
'rel': '2'
}
all_metrics = {
'apples_list' : {'items': [apples, pears, bananas], 'operators': [equals, plus, end]},
'bananas_list' : {'items': [bananas, oranges, apples, kiwi], 'operators': [equals, plus, plus, end]},
'kiwi_list': {'items': [kiwi, apples, bananas], 'operators': [equals, plus, end]},
'pears_list': {'items': [pears, bananas, kiwi, oranges], 'operators': [equals, plus, plus, end]},
'oranges_list': {'items': [oranges, apples, bananas], 'operators': [equals, plus, end]}
}
current_metric = all_metrics['apples_list']
all_items = list(set([
item['name']
for each in all_metrics.keys()
for item in all_metrics[each]['items']
]))
def component(name, val, rel):
return html.Div(
id=name+'_div',
children=[dash_table.DataTable(
id=name,
columns=[
{"name": [name, 'abs'], "id": 'abs'},
{"name": [name, 'rel'], "id": 'rel'},
],
data=[
{
"abs": val,
"rel": rel,
}
],
style_table= {'maxWidth': '200'},
merge_duplicate_headers=True,
)
], style={'width':'120px'})
def combine_components(relationship):
relationship = relationship['items'][0]['name'] + '_list'
return html.Div(
children=[
val for pair in zip(
[
component(each['name'], each['val'], each['rel'])
for each in all_metrics[relationship]['items']
],
all_metrics[relationship]['operators']
)
for val in pair
],
style={'display': 'flex', 'flex-direction': 'row'}
)
app = dash.Dash(__name__)
# create callbacks for a component which is not yet in the layout
app.config.supress_callback_exceptions = True
app.layout = html.Div([
html.Div([
dcc.Dropdown(
id='dropdown',
options=[
{'label': j, 'value': j} for j in all_items
],
value=current_metric['items'][0]['name'],
style={'width':'120px', 'margin-bottom':'10px'},
searchable=True,
clearable=False
),
html.Div(
id='canvas',
children=combine_components(current_metric),
style={}
)
])
])
# @app.callback(
# Output('canvas', 'children'),
# [Input('dropdown', 'value')]
# )
# def update_metrics(value):
# relationship=str(value)+'_list'
#
# print(all_metrics[relationship]['items'])
#
# print([ Input(item['name'], 'n_clicks') for item in all_metrics[relationship]['items'] ])
#
# return combine_components(all_metrics[relationship])
@app.callback(Output('canvas', 'children'),
[Input(item+'_div', 'n_clicks') for item in all_items])
def update_metrics(*all_items):
ctx = dash.callback_context
if not ctx.triggered:
msg = 'None of the buttons have been clicked yet'
else:
clicked = ctx.triggered[0]['prop_id'].split('.')[0].split('-')[1]
print(f'clicked: {clicked}')
msg = f'Button {clicked} was most recently clicked'
value=clicked
relationship=str(value)+'_list'
return combine_components(all_metrics[relationship])
if __name__ == '__main__':
app.run_server(debug=True)