When app waiting to load I have doubled (greyed) parts with st.write and st.expander.
It is caused by “streamlit_authenticator”
Are you running your app locally or is it deployed?
locally and deployed
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
Share the link to your app’s public GitHub repository
Private
Share the full text of the error message (not a screenshot).
Not an error message
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.
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
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.