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

streamlit.errors.DuplicateWidgetID: There are multiple widgets with the same `key='set'`. #61

Closed jump2cn closed 6 months ago

jump2cn commented 7 months ago

hi team, I get this error when I want to add the cookie.set code into a function. and sometime the error will report with other keys like 'init', 'get_all', and so on.

demo test log

even if I cache the cookie manager , it also gets warring and error

import streamlit as st
import extra_streamlit_components as stx

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

def set_cookie():
    get_manager().set('key_test2', 'test2')

st.write("This is a test page.")

get_manager().set('key_test', 'test')

set_cookie()
st.write('set by function')

demo log3

图片

E-delweiss commented 7 months ago

Same problem here. FYI a quick fix may be to add key like :

cookie_manager.set("a","b", key=2)
cookie_manager.set("a","b", key=3)

I agree with you, it's not convenient hop there will be a fix.

Mohamed-512 commented 6 months ago

Added batch set method in version 0.1.70