Deployment of dash app

Hello comunity!

I am here to ask for advice.

I have a Flask app with dash instance within like so (i dropped everything unrelated, but there is also flask-login and redis as session storage):

def create_app():
    app = Flask(__name__)
    app.config.from_pyfile("config.py")   
    with app.app_context():
        from sweater.dashboards.routes import create_dash_instance
        app = create_dash_instance(app, server_ip)
        
        from sweater.dashboards import dash_bp
        app.register_blueprint(dash_bp)
    from werkzeug.middleware.proxy_fix import ProxyFix

    app.wsgi_app = ProxyFix(app.wsgi_app, x_for=1, x_proto=1, x_host=1, x_prefix=1)
    return app

My create_dash_instance func is pretty huge bc of all the callbacks, but here is main parts:

def create_dash_instance(app, server_ip):
    dash_app = Dash(__name__, server=app, url_base_pathname='/dashboard/', assets_folder=get_root_path(__name__) + '/assets/', external_stylesheets=[dbc.themes.BOOTSTRAP])
    dash_app.layout = html.Div([])
    return dash_app.server

And also i do have flask route to open dashboards with layout i need like so (it is also within create_dash_instance func):

@dash_bp.route("/dashboard_setup/<dashboard_code>", methods=['GET'])
    def dashboard_setup(dashboard_code):
    ...
    return redirect(url_for('/dashboard/'))

To clarify — that route opens the exact same layout. Only differences is in data. So basically it renders the same layout but with different data based on user’s choice. (data variety is around 30 different data sources, so it is inconveniente to use pages)

That is probably not the best way, but that is what i come up to.

I use gunicorn as wsgi server and nginx as reversed proxy server. Wsgi server is set to several processes.

Problem is when i open dash page with data source as a user and then reload page with f5 or refresh button. I am not stick to that page, but that page is still opened in some process or thread i guess. So i could get absolutelly new page after refresh. And if i have several users using dash at around the same time they could get their pages mixed up if they refresh.

My guess that it is happening because i did not set sessions right, but i might be wrong.

Does anybody willing to give me any suggestions on how to fix that?
I could provide any code if needed.