How to fix DuplicateWidgetID: There are multiple identical st.button widgets when there are no duplicate keys in Streamlit

I am trying to Implement a pause and resume button in my program.

But I get the error: DuplicateWidgetID: There are multiple identical st.button widgets with key='pause_button' . How do I fix this when there are no duplicate keys?

Here is a snipnet of my code:

while st.sidebar.button(label="Pause", key='pause_button'):
    if st.sidebar.button(label="Resume", key='resume_buton'):
        continue
    time.sleep(10)

Or what is best way to implement a pause button in my simulation program?

1 Like

Hello John,

I’m having the same issue, did you happen to find a solution for this?

same issue, why is that?

Because the code is creating multiple identical st.button widgets with key=‘pause_button’`. What is not clear?

@JohnAnih

As per my understanding, you are trying to create multiple pause button with same key. my solution to you is to change the keys like pause1_button, pause2_button. here your functionality will not affecting anyways.

give a try and let us know

Hi, I had the same problem and I added a random key to the original key

def plot_button(*args, **kwargs):
    rkey = hex(random.getrandbits(64)).upper()[2:]
    retries = 3
    while (retries > 0):
        try:
            kw = kwargs.copy()
            kw['key'] = kwargs['key']+rkey
            stb = st.button(*args, **kw)
        except DuplicateWidgetID: 
            rkey = hex(random.getrandbits(64)).upper()[2:]
        else:
            break
        finally: 
            retries -=1
        if retries <= 0: 
            raise(DuplicateWidgetID)        
    return stb