Hello, I’ve tried tried fixing this error for an day now and have unfrtunetly not gotten a response in the discord so I’ll just ask here.
I’m experiencing an issue where the streamlit radio on_change fires the function without the value actually changing but rather on the initial page render which is causing other problems in my app.
I do not know whether my implementation is just not ideal or if it’s an actual bug with the st.radio on_change parameter.
To reproduce:
download / copy the files in here
and run the home.py file using ‘streamlit run home.py’
Is this an unintended bug or am I just not understanding the st.radio correctly ??
Would appreciate any help on this ;D
There is a separate keyword to pass the arguments. This is so on_change gets assigned a function object and not the output of that function. (Note the extra comma to pass the argument as a tuple of size 1.)
There is also another fact that the radio button does not output its value until after the callback function is run. So number_inpt_choice will not have the intended value until after the page loads.
If you set the radio button to have key="number_inpt_choice" then upon clicking it (and instantaneously before the on_change function is run), you can access st.session_state.number_inpt_choice within the on_change function if you need to.
Thank you so much, got the implementation working and it all makes sense now, can finally move onto the next part of my app after finally getting this error resolved ;D
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.