This error occurs when you use the st.streamlit_option_menu.option_menu()
function without providing a unique key
argument. The key
argument is necessary to ensure that Streamlit can properly track and update the state of the widget.
To fix this error, simply add a key
argument to the st.streamlit_option_menu.option_menu()
function call. Here’s an example:
import streamlit as st
# Create a list of options
options = ["Option 1", "Option 2", "Option 3"]
# Add an option menu to the Streamlit app
selected_option = st.streamlit_option_menu.option_menu(
"Select an option",
options=options,
index=0,
key="my_unique_key"
)
# Do something with the selected option
st.write("You selected:", selected_option)
In this code, the key
argument is set to “my_unique_key”. You can replace this with any unique string that describes the purpose of the option menu in your app.
By adding a key
argument to the st.streamlit_option_menu.option_menu()
function call, you ensure that Streamlit can properly track and update the state of the widget.