Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Streamlit 1.32.1+ with streamlit_antd_components issue #183

Open
wyzdic opened this issue Jul 30, 2024 · 5 comments
Open

Streamlit 1.32.1+ with streamlit_antd_components issue #183

wyzdic opened this issue Jul 30, 2024 · 5 comments
Labels
help wanted Extra attention is needed

Comments

@wyzdic
Copy link

wyzdic commented Jul 30, 2024

Streamlit-Authenticator (0.32, 0.33) streamlit_antd_components (0.3.2)
In streamlit 1.32.0 the code runs very stably, when I update to a later version of streamlit (including the latest 1.37), streamlit-authenticator does not work properly with streamlit_antd_components.
When I log in to the main page, the menu menu will not be displayed, and I need to manually refresh it once by clicking the R key on the keyboard. If I refresh the web page, the menu menu will disappear, and I need to reuse the R key to refresh it to be displayed, if I don't use Streamlit-Authenticator, streamlit_antd_components work fine, I removed all the other redundant code, leaving only the most basic part to reproduce the problem, do you encounter the same problem? Here's the code I reproduced:

`
import streamlit as st
import streamlit_authenticator as stauth
import streamlit_antd_components as sac
import yaml
from yaml.loader import SafeLoader

st.set_page_config()

with open('config/config.yaml', encoding='utf-8') as file:
config = yaml.load(file, Loader=SafeLoader)

authenticator = stauth.Authenticate(
config['credentials'],
config['cookie']['name'],
config['cookie']['key'],
config['cookie']['expiry_days'],
config['preauthorized'],
)
if not st.session_state["authentication_status"]:
login_in = authenticator.login(
location='main',
)
if st.session_state["authentication_status"]:
with st.sidebar:
menu_select = sac.menu(
[
sac.MenuItem('Home', icon='house-fill'),
sac.MenuItem('update', icon='calendar2-range-fill', tag=[sac.Tag('New', color='red')]),
sac.MenuItem('database', icon='file-earmark-font-fill'),
],
open_all=False,
height=680,
indent=20,
index=1,
key='menu_select',
size='md',
)

`

@mkhorasani mkhorasani added the help wanted Extra attention is needed label Jul 30, 2024
@wyzdic
Copy link
Author

wyzdic commented Aug 19, 2024

After actual testing, I found out that it was extra_streamlit_components component that caused the problem, I tried to comment out the extra_streamlit_components related code in Streamlit-Authenticator, the problem never happened again when the program was running, can I change the package of cookie management to fix the problem?

@wyzdic
Copy link
Author

wyzdic commented Aug 19, 2024

Update:
I found a temporary solution
Modify Streamlit_Authenticator/models/cookie_model.py
Comment: # self.token = self.cookie_manager.get(self.cookie_name)
Modified to (streamlit==1.37)
if st.context.cookies.get("stauth_cookie"):
self.token = st.context.cookies["stauth_cookie"]
It's working fine now

@mkhorasani
Copy link
Owner

mkhorasani commented Aug 19, 2024

Update: I found a temporary solution Modify Streamlit_Authenticator/models/cookie_model.py Comment: # self.token = self.cookie_manager.get(self.cookie_name) Modified to (streamlit==1.37) if st.context.cookies.get("stauth_cookie"): self.token = st.context.cookies["stauth_cookie"] It's working fine now

I considered doing this myself and perhaps I will implement it, but until Streamlit has a native way to read and write cookies, then I cannot fully replace the streamlit cookies manager.

@wyzdic
Copy link
Author

wyzdic commented Aug 19, 2024

I guess this works as a temporary solution until streamlit natively supports cookies, maybe the st.context in streamlit 1.37 means that this day won't be too long?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants