Button session_state not working properly

def disable():
    #st.sidebar.title('File Upload and Processing')
    st.session_state.disabled = True

def main():

    #keys and uploads are active
    if 'disabled' not in st.session_state:
        st.session_state.disabled = False

    if 'clicked_pred'not in st.session_state:
      st.session_state.clicked_pred = False

    with st.sidebar:
        st.write('### Upload :orange Mammogram image/images')
        files = st.file_uploader("Upload a file", key='file_upload_widget'  ,  accept_multiple_files= True ,
                                type = ['dicom' , 'dcm' , 'zip' ] , disabled = st.session_state.disabled)


        keys = st.button(f"### :green[Run Detector]" , help = 'Run Model prediction on Image' , use_container_width=True ,
                    on_click=disable()  ,disabled = st.session_state.clicked_pred )

    for file in files:
         process......
         if keys:
                  #I should shut download button and keys button after this line
                   output.........

what is happening here is weired, 1st the upload button starts the session with disabled state = True

2nd the keys button get disabled after clicked twice not once??

for your kind advice.

thanks

Hi @Ali_Sultan!

The issue is likely here:

When you have an on_click, you want the argument to be the function itself, without actually calling it. What I mean is:

on_click=disable – passes the function itself, and that function will be called when the button is clicked
on_click=disable() – calls the function right away (when you create the button), and passes the output of that function as the on_click value.

Removing the () will likely fix the issue.