I just started using st.form , I did not find this question anywhere. Please bear with me.
This is my code.
with st.form('form1'):
parameter1 , parameter2 = st.columns(2)
with parameter1:
grps = ['ABC','DEF']
grp= st.selectbox('Account',grps )
with parameter2:
if grp == 'ABC':
items = ['ABC1','ABC2','ABC3']
else:
items = ['DEF1','DEF2']
items = st.multiselect('Items',items)
submit_form = st.form_submit_button('Submit')
st.write(grp,items)
When I select the first select box to DEF , it should automatically pick the next multiselect based upon the first variable value but here it is not considering the grp input.
It is still showing ABC1 , ABC2 , ABc3 values , even if I select DEF grp.
when I hit submit , it is only displaying the grp value but not the multi select one.
Hi @Santosh, A form is meant to batch-process inputs; if you have conditional logic for any widget, dont put those widgets in a form. Check your revised code below:
Thanks! @gaganmanku96. I was thinking since since Streamlit runs from top to bottom inside the forms.
So I thought it would pass the first input widget value to the second input widget. Well a good thing to know
Thanks! @Shawn_Pereira. I’m trying to create a operational report so form is much needed for me. I’ll do some trial and error methods and post it here if I found any work around
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.