Hello everyone! like the title says, I am currently getting the following error
StreamlitDuplicateElementKey: There are multiple elements with the same
`key='sidebar-dropdown'`. To fix this, please make sure that the `key` argument is
unique for each element you create.
I understand this error is caused by either two different elements having the same key, or it can also happen because the same element with a key was called multiple times in one rerun. However, I don’t see anything that would be causing something like that to happen in my code. I asked the Streamlit docs bot as well, and it said there was nothing in any of my files that would cause the widget containingsidebar'dropdown
to be rerun. Maybe someone can offer some insight on this? This page of my app is pretty small right now so I will post the code for it here:
import streamlit as st
from logExtractMain import log_extract_dataframe
from logVisualizeMain import logVisualize
import sessionviewPage
st.set_page_config(page_title="Syanpse VX Log Parser")
st.set_page_config(layout='wide')
st.markdown("""
<style>
.st-key-sidebar-dropdown {
margin-bottom: 2vh;
}
/* CSS for the selectbox label */
.st-key-sidebar-dropdown label p{
color: #ffffff;
font-size: 18px;
font-weight: bold;
}
</style>
""", unsafe_allow_html=True)
#--------------------------------------- PAGE CODE --------------------------------------------------------------
if "data_frame" not in st.session_state or "parsed_log" not in st.session_state:
st.session_state["data_frame"], st.session_state["parsed_log"] = logVisualize()
if "show_sheet" not in st.session_state:
st.session_state.show_sheet = False
data_frame = st.session_state["data_frame"]
# Import quickviewPage now that we have the value for data_frame
import quickviewPage
# Add selectbox to sidebar
add_selectbox = st.sidebar.selectbox(
'View a specific session:',
data_frame['Start Time'],
index=None,
placeholder="No session selected",
key='sidebar-dropdown',
)
# Add Log Spreadsheet button to the sidebar
def toggle_sheet():
st.session_state.show_sheet = not st.session_state.show_sheet
st.sidebar.button('Log Spreadsheet', on_click=toggle_sheet)
if st.session_state.show_sheet:
st.dataframe(data_frame)
# Call the default quickviewPage
if st.session_state['sidebar-dropdown'] == None:
quickviewPage.loadQuickviewPage()
elif st.session_state['sidebar-dropdown'] is not None:
sessionviewPage.loadSessionviewPage()
There are two other small files to my app that are called at the bottom. I can provide those if needed too but wanted to see if anyone saw anything here. Neither of them rerun the above file. Thanks!
(Streamlit v 1.46.1, Python 3.13.5, running locally)