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
466 stars 59 forks source link

Does the Cookie Manager accept Dicts at all? #39

Closed mansidak closed 6 months ago

mansidak commented 1 year ago

Pretty much the heading. I'm attempting to add a dict as a cookie ( instead of a string, as shown in the gif) and it just doesn't get added :/

Socvest commented 11 months ago

Yes it does. Try this:

import json
val = json.dumps({'name':'Jacob'})

cookie_manager = CookieManager()
cookie_manager.set("cookieName", val)

# refresh browser
cookie_read = cookie_manager.get("cookieName") # will get json object
st.write(cookie_read)

Refresh browser and check

Mohamed-512 commented 6 months ago

only primitive types can be added, as the web as we know it was built to accept cookies as strings. you can stringify the dict as suggested by @Socvest