Closed LeoGrin closed 2 years ago
This is not a bug, you are required to supply a unique key for the each of the cookie_manager.get
calls, as both have the same defualt key and content. This is a regulation by Streamlit to not have two componets that are identical in everything.
The following snippet will spit out the same error:
import streamlit as st
st.number_input("n1")
st.number_input("n1")
A fix to this problem is to add a key to the second call of cookie manager as follows:
import streamlit as st
import extra_streamlit_components as stx
cookie_manager = stx.CookieManager()
print(cookie_manager.get("cookie"))
print(cookie_manager.get("cookie", key="second"))
Ok thank you!
I see what you mean, but as "get" doesn't really create a widget, I think it's a weird behavior and could maybe be dealt with internally in Extra-Streamlit-Component.
Anyway, thank you for your time and your library !
You're welcome! You might be right, getting a cookie can be abstracted a bit more. But setting a cookie requires a communication between the Streamlit server and the browser, which needs a component initialized to do specifically this. But this will give an inconsistent developer experience as a trade off.
Minimal code:
Error: