arnaudmiribel / streamlit-extras

Discover, try, install and share Streamlit re-usable bits we call "extras"!
https://extras.streamlit.app
Apache License 2.0
737 stars 125 forks source link

Add local_storage #233

Open sfc-gh-jcarroll opened 3 months ago

sfc-gh-jcarroll commented 3 months ago

Add a local_storage extra for easier interaction with browser localStorage

It's still a bit buggy at times, I get periodic "app resets" (the session_state still exists but widget values get reset) which I can't explain. Like everything gets unmounted. May have to do with the way st_js updates very quickly and some race condition.

netlify[bot] commented 3 months ago

Deploy Preview for phenomenal-crepe-0effec ready!

Name Link
Latest commit ae446bb27c85002b4dc766022cdd2a8c38db7ebb
Latest deploy log https://app.netlify.com/sites/phenomenal-crepe-0effec/deploys/668895f2c07cc70008c9017d
Deploy Preview https://deploy-preview-233--phenomenal-crepe-0effec.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

bhargavmodak commented 1 month ago

I've tried this to test in an application for my own testing, and I think it would be useful for your reference before this is merged:

How to test:

You can either log-in directly with the above deployment (or clone and deploy yourself).

[!NOTE] The Google OAuth Consent screen has to be opened in a new tab. This is related to Streamlit Issue #7123: Link redirect. Read more about how I did it in Chapter 2 of the repo above.

  1. After logging in, you should be redirected to the /auth route of the app above. Here I try to save the google session token pair into local storage.
    1. Check the local storage as it processes. You should see st_localstorage_g_session.
  2. Issue 1 occurs here.
  3. If you go into an infinite loop, reload the page. Then it works.
  4. Once you log in, you can look around the app. The /auth route is hidden.
  5. Try to log out.
  6. Issue 2 occurs here.

Issues

ISSUE 1

The processing goes into an infinite loop even if the data has been set in local storage.

ISSUE 2

When logging out, it says 'Bad message format : Bad 'setIn' index # (should be between [0, 1])


I'm assuming both issues are occurring due to the local storage. I've implemented it at st_local_storage.py.