Hi there, I’m trying to make a structured project, generalizing tabs to make them reusable in other projects. The way I’m trying to do this is by having one main file that calls function/structures from other files. Where each file it calls corresponds to one tab.
The callback of the drop-down on the first tab is calling a function from another file, the function will do some data processing and return the figure section of my graph. The problem is that my graph doesn’t seem to show any data. There are no callback errors raised, so that can’t be the problem. Also, I’ve tested the code in one file, so that can’t be the problem either. Do you have any idea?
CODE IN MAIN:
import tab1
import tab2
import tab3
import tab4
app.layout = html.Div([
html.Div(
dcc.Tabs(
tabs=[
{'label': 'Locatie', 'value': 1},
{'label': 'Usage Over Time', 'value': 2},
{'label': 'Predictions', 'value': 3},
{'label': 'Target Pricing', 'value': 4},
],
value=1,
id='tabs',
vertical=vertical,
style={
'height': '100vh',
'borderRight': 'thin lightgrey solid',
'textAlign': 'left'
}
),
style={'width': '20%', 'float': 'left'}
),
html.Div([dcc.Dropdown(id = 'tab-output',value = "Oogkliniek de Horsten"),
dcc.Graph(id='graph'),
html.Div(' '.join(get_sentences(10))),
],
style={'width': '80%', 'float': 'right'})
], style={
'fontFamily': 'Sans-Serif',
'margin-left': 'auto',
'margin-right': 'auto',
})
@app.callback(Output('tab-output', 'options'),
[Input('tabs', 'value')])
def display_content(tab):
if tab == 1:
return tab1.tab_content(gbq_data)
if tab == 2:
return tab2.tab_content(gbq_data)
if tab == 3:
return tab3.tab_content(gbq_data)
if tab == 4:
return tab4.tab_content(gbq_data)
@app.callback(Output('graph', 'figure'), [Input('tab-output', 'value')])
def update_graph(value):
return tab1.get_graph[gbq_data,value]
if __name__ == '__main__':
app.run_server(debug=True, port = 3005)
CODE IN tab1.py:
def tab_content(gbq_data):
return [{'label': i,'value': i} for i in pd.unique(gbq_data['dim_locatie_naam'])]
def get_graph(gbq_data, loc_name):
totaalcore_bench = gbq_data[gbq_data['dim_datum_jaar']==2016].drop_duplicates(['dim_locatie_id','agg_totaalscore_locatie'])['agg_totaalscore_locatie'].mean()
aandoening_bench = gbq_data[gbq_data['dim_datum_jaar']==2016].drop_duplicates(['dim_locatie_id','agg_aandoeningspecifieke_score_locatie'])['agg_aandoeningspecifieke_score_locatie'].mean()
kwal_algemeen_bench = gbq_data[gbq_data['dim_datum_jaar']==2016].drop_duplicates(['dim_locatie_id','agg_kwaliteitalgemeen_score_locatie'])['agg_kwaliteitalgemeen_score_locatie'].mean()
totaal_loc = gbq_data[(gbq_data['dim_locatie_naam']==loc_name) & (gbq_data['dim_datum_jaar']==2016)]['agg_totaalscore_locatie'].iloc[1]
aand_loc = gbq_data[(gbq_data['dim_locatie_naam']==loc_name) & (gbq_data['dim_datum_jaar']==2016)]['agg_aandoeningspecifieke_score_locatie'].iloc[1]
kwal_loc = gbq_data[(gbq_data['dim_locatie_naam']==loc_name) & (gbq_data['dim_datum_jaar']==2016)]['agg_kwaliteitalgemeen_score_locatie'].iloc[1]
data = [
{ # Locatie
'x': ['Aand','Alg','Totaal'],
'y': [aandoening_bench,kwal_algemeen_bench,totaalcore_bench],
'name': 'Benchmark',
'marker': {'color': 'rgb(255, 0, 255)'},
'type': 'bar'
},
{ # Benchmark
'x': ['Aand','Alg','Totaal'],
'y': [aand_loc,kwal_loc,totaal_loc],
'name': 'Locatie',
'marker': {'color': 'rgb(0, 0, 255)'},
'type': 'bar'
}]
return {'data': data,
'layout': {'margin': {
'l': 30,
'r': 0,
'b': 30,
't': 0},
'legend': {'x': 0, 'y': 1}}}
Greetings, Tom