I have built my dash app using flask as my main framework because i wanted to protect my dashboard views. The error i keep getting is the DuplicateCallbackOutput, everytime i reload my page.
#DASH APP
with flask_app.app_context():
#render dashboard template
dashboard_template = render_template(‘dashboard.html’,title=“Dashboard”)
dashboard_template = dashboard_template.replace(‘{app_entry}’, ‘{%app_entry%}’)
dashboard_template = dashboard_template.replace(‘{config}’, ‘{%config%}’)
dashboard_template = dashboard_template.replace(‘{scripts}’, ‘{%scripts%}’)
dashboard_template = dashboard_template.replace(‘{renderer}’, ‘{%renderer%}’)#initialize dash_app dash_app.index_string = dashboard_template dash_app.config.supress_callback_exceptions = True #Layout dash_app.layout = html.Div()
#dash_app urls can be accessed once the user has logged in
dash_app = protect_views(flask_app, dash_app)#DASHBOARD ROUTE
@flask_app.route(‘/dashboard’)
@login_required
def dashboard():
vdata = VipimoData(current_user.token)#validate token before proceeding if not vdata.validate_token(): return redirect(url_for('logout')) #The rest of the steps is for validated tokens get_locations = vdata.get_locations() if 'success' in get_locations and len(get_locations['success']) > 0: locations = get_locations['success'] nodes_per_location = {} for i in locations: if len(i['nodes']) > 0: nodes_per_location.update({i['name']:i['nodes']}) locations_dropdown = [{'label':location, 'value':location} for location in nodes_per_location.keys()] #dash_app layout = Layout() dash_app.layout = layout.default(locations_dropdown) """ @dash_app.callback( Output('locations', 'value'), [Input('location', 'value')], [State('locations', 'value')] ) def set_location(value, state ): print(value, state) return locations_dropdown[0]['value']""" #cache @cache.memoize() def data_store(node, start_date=None, end_date=None): #get data node_data = vdata.get_data(node, start_date, end_date) #graph data graph_data = [] if node_data.empty == False: columns = node_data.columns.tolist() new_columns = [ c for c in columns if c not in ['Timestamp', 'Coordinates', 'NodeID']] for c in new_columns: graph_data.append(go.Scatter( x=node_data['Timestamp'].tolist(), y=node_data[c].tolist(), name=c, line={'shape':'spline'} )) return graph_data def generate_graph(node_name, graph_data): return { 'data': graph_data, 'layout': go.Layout( xaxis={'title':'Timestamp'}, yaxis={'title':'Measurements'}, title='Sensor - {0}'.format(node_name) ) } @dash_app.callback( Output('vipimo-graph', 'figure'), [Input('dstore', 'children')] ) def update_graph(node): graph_data = data_store(node) if node and graph_data: return generate_graph(node, graph_data) #return redirect('/dash-board') return dash_app.index(current_user=current_user)