Multiselect widget not working as expected inside streamlit form

Hi,

I am facing an issue with st.multiselect widget. st.multiselect not working as expected inside streamlit form st.form. After selecting multiple options through the multi select element, on form submission, the multiselect widget giving empty value.

import streamlit as st

with st.form(key="async_testing_config"):
        # Components : Select async api endpoints for testing.
        components = st.multiselect(
            "Select async api endpoints",
           external_call_to_aws_api_to_get_list_of_endpoints(),
            key="components"
        )

        # Submitted - BOOLEAN
        Submitted = st.form_submit_button("Submit")
        if Submitted:
            print("endpoints: ",components)

I’m using

  • streamlit 1.28.2 (running on localhost)
  • Python 3.9

Highly appreciate any critical/helpful information on this issue!!

Thank you!

Hello Pradeep :wave:,

The multiselect within a form works just fine for me, which brings me to the conclusion that the problem might be due to the use of print() instead of st.write() to display the values.

On the last line of your code, try doing:


st.write("endpoints", components)

Hello Rimano, Thanks for the reply. multiselect streamlit widget working as expected when options provided to it are static but when the options are dynamic, it is not working as expected. I have raised issue on streamlit github. checkout - Link

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.