Update value in selectbox in real--time

How do I update the “options” of the selectbox dynamically?

Here is a mockup that I created. In the below mockup, I can only set the value for “options” only after I have fetched the data.

Here is a minimum non-working example

import streamlit as st
import time
def main():
 st.session_state['choice'] = list(range(2))
st.selectbox("myoptions", options=st.session_state['choice'])
while True:
 st.session_state['choice'] = list(range(5))
 time.sleep(2)

The list of options in select box do not update

1 Like

@Charly_Wargnier: I see that you are a pretty active member of the community and a developer advocate. In that regards, can I ask if you have any suggestions?

Sorry for bothering, got the solution

import streamlit as st
import time
import random
def skeleton():
    left, right = st.columns(2)
    with right:
        numbers = st.empty()
    return left, right, numbers

left, right, numbers = skeleton()
while True:
    with right:
        with numbers.container():
            st.selectbox('food',random.sample(range(10, 40), 4))
            time.sleep(2)


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