How manual selection works
masterThe manual_select parameter allows you to programmatically move the menu to a specific index. Because this parameter behaves like a button, you should not pass a constant value to it. Instead, you should pass the desired index only when an event occurs (like a button click or a process completion) and then reset it to None to avoid repeated triggers.
Example pattern for manual selection using st.session_state:
if st.session_state.get('switch_button', False):
# Calculate the next index
st.session_state['menu_option'] = (st.session_state.get('menu_option', 0) + 1) % 4
manual_select = st.session_state['menu_option']
else:
manual_select = None
selected4 = option_menu(
None,
["Home", "Upload", "Tasks", 'Settings'],
icons=['house', 'cloud-upload', "list-task", 'gear'],
orientation="horizontal",
manual_select=manual_select,
key='menu_4'
)
st.button("Move to Next", key='switch_button')