Multi-page app with session state

Hello @OlliePage, your IDE tries to run your app as a regular python script, but in that case it won’t load a ReportContext object.

In your case, try to use this _get_state() function. When run as a script, using a module like sys to keep your session state should work fine.

import sys

# ...

def _get_state(hash_funcs=None):
    try:
        session = _get_session()
    except (AttributeError, RuntimeError):
        session = sys

    if not hasattr(session, "_custom_session_state"):
        session._custom_session_state = _SessionState(session, hash_funcs)

    return session._custom_session_state

1 Like