Mohamed-512 / Extra-Streamlit-Components

An all in one place, to find complex or just not available components by default on streamlit.
Apache License 2.0
484 stars 60 forks source link

Cannot set cookie shortly after creating CookieManager #9

Closed muskedunder closed 3 years ago

muskedunder commented 3 years ago

If I try to set a cookie using a newly created CookieManager, I get errors saying st.session.state.cookies is None. Minimal example:

import time
import extra_streamlit_components as stx

SLEEP_TIME = 1

cookie_manager = stx.CookieManager()
time.sleep(SLEEP_TIME)
cookie_manager.set('yummy_cookie', "nomnom")

If SLEEP_TIME is too low I get the error

  File "/home/colin/anaconda3/envs/cookiestest/lib/python3.7/site-packages/streamlit-1.0.0-py3.7.egg/streamlit/script_runner.py", line 354, in _run_script
    exec(code, module.__dict__)
  File "/home/colin/Documents/minut/py-owl/test_cookies.py", line 8, in <module>
    cookie_manager.set('yummy_cookie', "nomnom")
  File "/home/colin/anaconda3/envs/cookiestest/lib/python3.7/site-packages/extra_streamlit_components/CookieManager/__init__.py", line 63, in set
    st.session_state.cookies.update({cookie: val})
AttributeError: 'NoneType' object has no attribute 'update'
Mohamed-512 commented 3 years ago

Fixed on 0.1.46. You can get the new update through pip.