I’m building my webapp based on combination of Flask and Dash. Basically, concept is exactly the same as presented here: Embed Multiple Dash Apps in Flask with Microsoft Authentication | by Steve Kiefer | Towards Data Science. What I would like o achieve now is Dash app with 2-3 tabs and for sake of clarity it would be great to have those 2-3 apps (each per tab) in separate files.
The point is that Dash apps are attached to Flask in init.py via:
def create_app(config_class): app = Flask(__name__) with app.app_context(): # register blueprints from app.main import bp as bp_main app.register_blueprint(bp_main) from app.dashapps import bp as bp_dashapps app.register_blueprint(bp_dashapps) # Regiester Dash apps # Dash app: start page from app.dashapps.dashapp_start_screen import add_dash as add_dashapp_start_screen app = add_dashapp_start_screen(app, config_class)
So app object is in fact Flask.
In Dash files app is created within a procedure:
def add_dash(server, login_reg = True): external_stylesheets = [ dbc.themes.BOOTSTRAP, ] app = dash.Dash( server = server, url_base_pathname = URL_BASE, suppress_callback_exceptions = True, external_stylesheets = external_stylesheets )
And now, if I go through example URL Routing and Multiple Apps | Dash for Python Documentation | Plotly I need to import app object into each Dash app (app1 and app2). How to do that? In my case app is created on the go and hidden in procedures. Is that feasible?