Hi team,
I am trying to get a multiselect option based on certain inputs from the user. The list which I need to display is not deterministic. I have pasted the sample codes here.
naming.py --------------------> sample code to get a non-deterministic list
def show_names(name):
if name == "Roy":
list1 = ['Riya','Ananya','Tanya','Sanya','Nikita']
elif name == "Sen":
list1 = ['Tarun','Arun','Bob','Karan','John']
return list1
post1.py -----------------------> First trial code to achieve multiselect:
import streamlit as st
import SessionState
import naming as n
def inp_det(type):
if type == 'source':
st.write('Enter name (Roy/Sen)')
name = st.text_input('Source name')
elif type == 'destination':
st.write('Enter name (Roy/Sen)')
name = st.text_input('Destination name')
return name
def main():
state = SessionState.get(rerun = False, prepro_steps=0)
name = inp_det('source')
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:
listnames = n.show_names(name)
selectednames=st.multiselect('Select your names',listnames)
st.write(selectednames)
if __name__ == "__main__":
main()
post2.py -----------------------> Second trial code to achieve multiselect:
import streamlit as st
import SessionState
import naming as n
def inp_det(type):
if type == 'source':
st.write('Enter name (Roy/Sen)')
name = st.text_input('Source name')
elif type == 'destination':
st.write('Enter name (Roy/Sen)')
name = st.text_input('Destination name')
return name
def main():
state = SessionState.get(rerun = False, prepro_steps=0)
name = inp_det('source')
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:
listnames = n.show_names(name)
for ln in listnames:
selectednames=st.checkbox(ln, value=False, key=None)
st.write(selectednames)
if __name__ == "__main__":
main()
The issue is in both the cases, the multiselect disappears as soon as I select one option. Is there any way for me to select multiple options after some input from user and capture those selected options?
Streamlit: version 0.62.1
Python: version 3.7.4
Browser (Google chrome): Version 83.0.4103.116