question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DuplicateWidgetID when you change the state of a widget with a button

See original GitHub issue

Summary

There is a button “change” that should change the state of a checkbox from True to False. If it was True by default and then you click the button, then it is changing. But if it was False by default and then a user checked and made it True, then there is DuplicateWidgetID exception when you click the “change” button.

Steps to reproduce

import streamlit as st

a = st.empty()
value = a.checkbox(label='test', value=False)
# user checks the checkbox => value is True again
if st.button('change'):
    value = a.checkbox(label='test', value=False)
    # here we have an error "DuplicateWidgetID: There are multiple identical st.checkbox widgets with the same generated key."

Expected behavior:

I expect that the checkbox will change the value from True to False.

Actual behavior:

DuplicateWidgetID Excetion

Is this a regression?

don’t know

Debug info

  • Streamlit version: Streamlit, version 0.60.0
  • Python version: Python 3.7.6
  • Using Conda: yes
  • OS version: macOS 10.15.4 (19E287)
  • Browser version: 84.0.4147.135 (Official Build) (64-bit)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
nthmostcommented, Aug 28, 2020

Yep, repro’d just now. Thanks for the sample code and nice writeup!

0reactions
kmcgradycommented, Dec 30, 2021

Ah Thanks @Musalappagaridevendrareddy ! This has been resolved with our new state model. Your example does work as expected. This can also be handled without st.empty and using callbacks (run before the script run).

import streamlit as st

value = st.checkbox(label='test', value=False, key='test')

def handle_click():
    st.session_state.test = False

st.button('change', on_click=handle_click)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Duplicate Widget ID: streamlit - python - Stack Overflow
button widgets with key='1'. To fix this, please make sure that the key argument is unique for each st.button you create. how can...
Read more >
How to use the "key" field in interactive widgets API - Streamlit
All interactive widgets have “key” as the last argument in the argument list. Is there a way to get the key of the...
Read more >
How to force a Widget to redraw in Flutter? | by Jelena Lecic
We take initial value from the Widget and store it locally in the State ... presses the button, never again and this is...
Read more >
Advanced Streamlit: Session State and Callbacks for Data ...
Callback is the function that gets called when the input widget is triggered. Streamlit widgets that support callback are st.button() , st.radio ...
Read more >
Streamlit Tricks — Application Reruns on Every Widget Click ...
In order to control the state of the button "Load Data" , we will be using ... despite the trigger from the change...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found