Streamlit-authenticator causing st.write text to double

When app waiting to load I have doubled (greyed) parts with st.write and st.expander.
It is caused by “streamlit_authenticator”

  1. Are you running your app locally or is it deployed?
    locally and deployed
  2. If your app is deployed:
    a. Is it deployed on Community Cloud or another hosting platform?
    AWS EC2 + Lambda endpoint.
    Share the link to the public deployed app.
    Cannot give a login
  3. Share the link to your app’s public GitHub repository
    Private
  4. Share the full text of the error message (not a screenshot).
    Not an error message
  5. Share the Streamlit and Python versions.
    streamlit==1.28.0
    streamlit-authenticator==0.2.2

Previously I did not know what was causing this behavior, as stated here;

Minimal reproducible:

import time
import streamlit as st
import streamlit_authenticator as stauth


# ----User Auth -----

credentials = {
    'credentials': {
        'usernames': {
            'user': {
                'name': 'user',
                'password': '$2b$12$cOyquTvi52nzwDbny4z9Iu2ca0f/psvEWVyaQLY2bvDmOaI3pBU36'
            }
        }
    },
    'cookie': {
        'name': 'random_cookie_name',
        'key': 'random_signature_key',
    }
}
authenticator = stauth.Authenticate(
    credentials['credentials'],
    credentials['cookie']['name'],
    credentials['cookie']['key']
)

name, authentication_status, username = authenticator.login('Documentation', 'main')


if authentication_status == False:
    st.write('')
    st.error('Wrong number')

if authentication_status is None:
    st.warning('Usually here and there')

if authentication_status:
    def info():
        st.write('1. info')
        st.write('2. another info')
        st.write('')
        with st.expander('photo', expanded=False):
            st.markdown('keys')
        st.write('3. start')

    info()
    time.sleep(8)  # API call <-----

    authenticator.logout('Logout', 'main')

So; requests.post(endpoint, headers=headers) here time.sleep(int) is used to make a single request to Lambda in order to wake it up as it takes several seconds usually. I can reproduce this adding; time.sleep(15) before.

I dont know how to prevent.

Could you post an image about this doubled text? How does it look like in your case?

Of couse! Here; photo and start are doubled within time.sleep(int) duration . Password - abc

The ghost is from the first call to info(). Create a counter to determine how many calls are sent. Do not render the ui in the first call.

    def info():
        st.session_state.infocnt += 1

        # Hack: Send the info only from the second call.
        # The first call was the ghost.
        if st.session_state.infocnt >= 2:
            st.write('1. info')
            st.write('2. another info')
            st.write('')
            with st.expander('photo', expanded=False):
                st.markdown('keys')
            st.write('3. start')

Full code

import time
import streamlit as st
import streamlit_authenticator as stauth


# info counter to limit ui rendering.
if 'infocnt' not in st.session_state:
    st.session_state.infocnt = 0


# ----User Auth -----

credentials = {
    'credentials': {
        'usernames': {
            'user': {
                'name': 'user',
                'password': ('$2b$12$cOyquTvi52nzwDbny4z9Iu2'
                             'ca0f/psvEWVyaQLY2bvDmOaI3pBU36')
            }
        }
    },
    'cookie': {
        'name': 'random_cookie_name',
        'key': 'random_signature_key',
    }
}
authenticator = stauth.Authenticate(
    credentials['credentials'],
    credentials['cookie']['name'],
    credentials['cookie']['key']
)

name, authentication_status, username = authenticator.login(
    'Documentation', 'main')


if authentication_status == False:
    st.write('')
    st.error('Wrong number')

if authentication_status is None:
    st.warning('Usually here and there')

if authentication_status:
    def info():
        st.session_state.infocnt += 1

        # Hack: Send the info only from the second call.
        # The first call was the ghost.
        if st.session_state.infocnt >= 2:
            st.write('1. info')
            st.write('2. another info')
            st.write('')
            with st.expander('photo', expanded=False):
                st.markdown('keys')
            st.write('3. start')

    info()

    time.sleep(8)  # API call <-----

    authenticator.logout('Logout', 'main')

    # Reset here to make the hack works in subsequent runs.
    st.session_state.infocnt = 0

Brilliant :star_struck: ! Thanks!