Multiselect after a button click

Hello Streamlit experts,

I am fairly new to using Streamlit, so excuse me if my query seems very basic. I am trying to achieve the following:

  1. Get input from user
  2. On click of a button, run a function (say func1) which uses the input from user
    3.The func1 gives a list as output. Display the list as options from which the user can choose.
  3. After all options are selected, display the options.

I have used the following code to achieve the above:

import streamlit as st
import SessionState

session_state = SessionState.get(name="", button_sent=False)
button_sent = st.button("SUBMIT")
if button_sent:
    session_state.button_sent = True
if session_state.button_sent:
    temp_list = func1(<input paramters>)
    for num,name in enumerate(temp_list):
            options = st.checkbox(name, value=False, key=num)

Issue: The problem that I am facing is , whenever I select an option from the list, the list is displayed again. That is , if there are 5 elements in the list, on selection of 1 item, 10 items get displayed ( the same 5 repeated again)

If there is any clearer way to achieve what is needed, please do let me know.

Thanks in advance

Hey @Ananya_Roy, welcome to the community ! I don’t think any question is basic, it is always going to prove useful to other Streamlit newcomers :slight_smile:

I’m not sure I’m able to reproduce your problem though :confused: I’m using the almost similar following snippet :

import streamlit as st
import SessionState

session_state = SessionState.get(name="", button_sent=False)
button_sent = st.button("SUBMIT")
if button_sent:
    session_state.button_sent = True
if session_state.button_sent:
    temp_list = [str(i) for i in range(10)]
    for num,name in enumerate(temp_list):
        options = st.checkbox(name, value=False, key=num)

Can you put an image of what is displayed ? Maybe it has to do with the func1 method you are using too, if you can provide the code for it ?

Fanilo