St.experimental dialog box on callback is not running for second time

Hi,

I am using streamlit_authenticator to create a login dialog box with below code. It works fine and dialog box automatically appears when user enter the website but once user closes it and click on the login button it does not apera

@st.experimental_dialog("Login")
def show_authentication_ui():
    tab1,tab2,tab3,tab4= st.tabs(["Login","Register","Forgot Password","Update Details"])
    with tab1:
        # Creating a login widget
        try:
            authenticator.login()
        except LoginError as e:
            st.error(e)
        
        if st.session_state["authentication_status"]:
            # authenticator.logout()
            # st.write(f'Welcome *{st.session_state["name"]}*')
            st.experimental_rerun() 
            # st.title('Some content')
        elif st.session_state["authentication_status"] is False:
            st.error('Username/password is incorrect')
        elif st.session_state["authentication_status"] is None:
            st.warning('Please Login to use GenAI for datanalysis')

    with tab2:
        # # Creating a new user registration widget
        try:
            (email_of_registered_user,
                username_of_registered_user,
                name_of_registered_user) = authenticator.register_user(pre_authorization=False)
            if email_of_registered_user:
                st.success('User registered successfully')
        except RegisterError as e:
            st.error(e)
    

I call button here

st.sidebar.button("Login",type="primary", on_click=show_authentication_ui())

Can you please help to troubleshoot?

Thanks,

1 Like

I am experiencing something very similar. Clicking the button with the experimental dialog the first time works, but then the second time nothing happens.

Are you coincidently running this on railway? I do not have this issue locally, nor do I have it on streamlit cloud or render, but on railway this seems to be an issue.

Using fragments in callbacks is not supported. Since dialogs are just an extension of fragments, dialogs can’t be used in callbacks at this time. (This will be clarified in documentation with the next release.)

As part of the work to de-experimentalize fragments, this is being investigated.

Thanks for your input, even for me its working on local but this error arises in cloud.

Thank you for answering the question! Since the update is yet to come,for now is any workaround available for this?

You’ll just need to call the dialog outside of the callback. I don’t know your workflow exactly, but a general-purpose alternative is to set a flag in Session State within a callback and include a check at the beginning of your script for that flag so you can call the dialog at the beginning (like it would be if it had run in a callback). That being said, a dialog is an overlay so it doesn’t really need to “called first;” you should be able to call it anywhere (and reset the flag so it doesn’t keep re-showing).

1 Like

As part of de-experimentalizing fragments and dialogs in version 1.37.0, fragments can now be nested and used in callbacks!

2 Likes