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

any way to suppress CachedWidgetWarning ? #70

Open aparkerguardian opened 2 months ago

aparkerguardian commented 2 months ago

the following code

import streamlit as st
import extra_streamlit_components as stx

st.write("# Cookie Manager")

@st.cache_resource
def get_manager():
    return stx.CookieManager()

cookie_manager = get_manager()

st.subheader("All Cookies:")
cookies = cookie_manager.get_all()
st.write(cookies)

c1, c2, c3 = st.columns(3)

with c1:
    st.subheader("Get Cookie:")
    cookie = st.text_input("Cookie", key="0")
    clicked = st.button("Get")
    if clicked:
        value = cookie_manager.get(cookie=cookie)
        st.write(value)
with c2:
    st.subheader("Set Cookie:")
    cookie = st.text_input("Cookie", key="1")
    val = st.text_input("Value")
    if st.button("Add"):
        cookie_manager.set(cookie, val) # Expires in a day by default
with c3:
    st.subheader("Delete Cookie:")
    cookie = st.text_input("Cookie", key="2")
    if st.button("Delete"):
        cookie_manager.delete(cookie)

gives a warning in the web app but not the terminal

image

aparkerguardian commented 1 month ago

well i used the following to get around it

with st.empty():
    @st.cache_resource
    def get_manager():
        return stx.CookieManager()

    cookie_manager = get_manager()
gabrielziegler3 commented 1 month ago

@aparkerguardian your solution is not working for me. Did you do something else? I actually missed the parentheses calling st.empty()