Summary
Page reruns after user input
Steps to reproduce
So after clicking out of the text input, the whole page reruns and the elements “shake”. If for example you click out of username onto password, sometimes it reruns and deselects that element, so you need to click again on it.
Can somebody help me find a fix?
Code snippet:
import streamlit as st
from user import *
if 'loggedIn' not in st.session_state:
st.session_state['loggedIn'] = False
if 'CurrentUser' not in st.session_state:
st.session_state['CurrentUser'] = ""
main = st.container()
loginSection1, loginSection2, loginSection3, loginSection4= st.columns(4)
vv1, vv2, vv3 = st.columns(3)
def show_login_page():
with loginSection4:
with vv3:
userName = st.text_input (label="User", key="userName", )
password = st.text_input (label="Password", key="pswdLogIn", type="password")
Login = st.button ("Login", key="loginButton",on_click=LoggedIn_Clicked, args= (userName, password))
def LoggedIn_Clicked(userName, password):
if login(userName, password):
st.session_state['loggedIn'] = True
st.session_state['CurrentUser'] = userName
else:
st.error("Invalid user name or password")
with main:
if not st.session_state.loggedIn:
show_login_page()