Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update for using st.session_state #43

Closed
saikumarmk opened this issue Sep 20, 2022 · 3 comments
Closed

Update for using st.session_state #43

saikumarmk opened this issue Sep 20, 2022 · 3 comments

Comments

@saikumarmk
Copy link
Contributor

As of Streamlit 1.12, the older API used to hack in a SessionState has been entirely deprecated (with an ugly hack to retrieve the Server from the GC) in favour of the built-in st.session_state. This comes from the advice of this gist here: https://gist.github.com/tvst/036da038ab3e999a64497f42de966a92

I'd be happy to contribute a pull request (I think it should be minor changes), though my only concern is that hydralit_components may require the old SessionState. Could any of the maintainers of either repository comment on this?

@TangleSpace
Copy link
Owner

you are most welcome to help fix this issue, thank you. The changes Streamlit made are large and we haven't had time yet to refactor the code, so any help would be greatly appreciated.

As for hydralit_components, it doesn't use the session state, so it will be fine, as all the state usage is only within the Hydralit package.

@saikumarmk
Copy link
Contributor Author

Update:

I've rewritten the code to avoid using the state hack, and instead use st.session_state. Additionally, the get method was replicated with this snippet of code:

        self._session_attrs = {'previous_app': None, 'selected_app': None, 'other_nav_app': None,
                               'preserve_state': preserve_state, 'allow_access': self._no_access_level, 'logged_in': False, 'access_hash': None}
        self.session_state = st.session_state

        if isinstance(self._user_session_params, Dict):
            self._session_attrs |= self._user_session_params

        for key, item in self._session_attrs.items():
            if not hasattr(self.session_state, key):
                self.session_state[key] = item

I've run this by the hydralit-example, and all seems functional (login, changing menus etc). I'll open a PR for further discussion.

@TangleSpace
Copy link
Owner

Thanks very much for your hard work saikumarmk!

latest package (1.0.14) has ben published.
pip install -U hydralit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants