Re-render selectbox after session_state change

Hey, streamlit community!

Currently, I am facing a problem, that my selectbox is not re-rendered even though the index value changes.

I have a button that changes the session state with the key date_index. After pressing the button and increasing this state, I would expect my date selectbox to rerender. But it does not.

Here a code snippet:

date = st.selectbox('Select a day', dates, format_func=day_name, key='date',
                            index=st.session_state['date_index'], on_change=update_date_index, args=(dates, ))

As you can see, I am using the key date_index in the session state. Is there a hack or an official that allows the re-render after the index value changes?

Thank you!

You can try this. It is rendering the previous value but somehow you need to select twice to choose an option from the selection… I do not know why
st.session_state[‘date’] = st.selectbox(‘Select a day’, dates, format_func=day_name, key=‘date’, index=dates.index(st.session_state[‘date’]), on_change=update_date_index, args=(dates, ))