Issue with st.cache_resource() - Widget state getting collapsed

I am using st.cache_resource for a function which is related to a widget(selectbox), on changing values in another widget(selectbox) which is completely unrelated to previously mentioned one, The first selectbox which shows options fetched using the function which uses st.cache_resource shows no options at all…

See the image below for how it looks before and after picking an option from the query select box at the end

Before:

After:

Code sample:

@st.cache_resource(ttl = 300)
def fetch_documents(_collection):
    documents = _collection.find()
    return documents

col2, col3, col4 = st.columns([4,4,6])

user = col2.text_input("Enter your MySQL Username", value = 'root')
password = col3.text_input("Enter Password", value = 'xxxxxxx', type = 'password') 

documents = fetch_documents(collection)
channel_names = [document["Channel_Details"]["Channel_Name"] for document in documents]

selected_channel = col4.selectbox("Select a channel", channel_names, key = 'selected_channel')

The last select box showing queries fetched from a dict having questions as key and respective sql queries as values:

selected_query = col6.selectbox("Select a query", list(queries.keys()))

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