DuplicateWidgetID when you change the state of a widget with a button
See original GitHub issueSummary
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:
- Created 3 years ago
- Comments:6 (1 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yep, repro’d just now. Thanks for the sample code and nice writeup!
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).