Widget Values of Session Reset Unexpectadly

I’ve got a functioning App using widgets such as button, checkbox, selectbox. Using SessionState and get_session()` to track each sessions variables, along with a reset button to reset the selected variables.

I also prefil the selectbox options upon opening the page in App from an API. This allows the most up-to-date selections available to the App. When i added this, i started to see stange behavior which previous selected boxes would be wiped out. I tried many different variations, including caching, and nothing seems to work. Below is code to help show the structure.

from .. import SessionState

def get_session():
session = SessionState.get(

# this is the API call to get list for selectbox
def get_opportunity_list(session):
    df = get_opps()
    return tuple([''] + list(df['opp_display']))

def write():
    session = get_session()
        if session.all_opps is None or len(session.all_opps) == 0:
              st.write('Getting refreshed Opporunity List')
              session.all_opps = get_opportunity_list(session)
              st.write('Using cached Opportunity List', session.customer_name)

    opps_list  = session.all_opps
    if opps_list is not None:
         st.write('len of all opps', len(opps_l))
         session.customer_name = empty_opportunity_id.selectbox(
            'Opportunity ID', opps_list, key=session.run_id)

    session.uploaded_file = empty_uploaded_file.file_uploader(
    "Upload XLS", type="xlsx", key=session.run_id )

    # i strangly lose this value, if I check it True, it flips back to False after I selected others
    session.consol_rating = empty_consol_rating.checkbox(
    "Add Consolidation Rating", False, key=session.run_id)

What happens if you don’t set key=session.run_id in any of your widgets?

@SimonBiggs - thanks for suggestion. Just tried that and same issue.