import re import dash_core_components as dcc import dash_html_components as html import dash_bootstrap_components as dbc from dash.dependencies import Input, Output, State from dash.exceptions import PreventUpdate from app_main import app from apps import app_contact, app_results, app_deconvolOP, app_estimateOP server = app.server # ========== Layout app.layout = html.Div([ dbc.Navbar( [ dbc.NavbarBrand("OP apportionment", href="/", className="ml-2 font-weight-bold"), dbc.NavbarToggler(id="navbar-toggler"), dbc.Collapse( [ dbc.NavLink("Results", href="/results", className="btn btn-success"), dbc.NavLink("Estimate your OP", href="/estimate", className="btn btn-link"), dbc.NavLink("Question & contact", href="/contact", className="ml-auto"), ], navbar=True, id='navbar-collapse' ), # dbc.Row( [ html.A( html.Img( src="/assets/img/logo_IGE.png", className="logo", height=50 ), href="http://www.ige-grenoble.fr" ), html.A( html.Img( src="/assets/img/logo_INERIS.png", className="logo", height=50 ), href="https://www.ineris.fr" ), html.A( html.Img( src="/assets/img/logo_LCSQA.png", className="logo", height=50 ), href="http://www.lcsqa.org" ), html.A( html.Img( src="/assets/img/logo_ADEME.png", className="logo", height=50 ), href="https://ademe.fr" ), ], id="nav-logo", className="ml-auto d-none d-md-block" ) ], ), html.Div(id='master-page-content'), dcc.Location(id='master-url', refresh=False) ]) # =========== Options app.title = "OP apportionment" # =========== Serve pages @app.callback( Output('master-page-content', 'children'), [Input('master-url', 'pathname')] ) def display_page(pathname): # return app_single.layout # Prevent accessing unallowed pages # if re.search("/.*\/.+", pathname): # raise PreventUpdate() if pathname is None or pathname == '/': return app_deconvolOP.layout elif pathname[:len('/results')] == '/results': return app_results.layout elif pathname[:len('/estimate')] == '/estimate': return app_estimateOP.layout elif pathname[:len('/contact')] == '/contact': return app_contact.layout else: return app_deconvolOP.layout # # return '404' # add callback for toggling the collapse on small screens @app.callback( Output("navbar-collapse", "is_open"), [Input("navbar-toggler", "n_clicks")], [State("navbar-collapse", "is_open")], ) def toggle_navbar_collapse(n, is_open): if n: return not is_open return is_open # ================================= if __name__ == '__main__': app.run_server(debug=True)