My code:
import streamlit as st
import pandas as pd
def main():
st.markdown("<h1 style='text-align: center; color: white;'>My Streamlit App</h1>", unsafe_allow_html=True)
menu = ["Admin","Manager","Employee"]
choice = st.sidebar.selectbox("User",menu)
if choice == "Admin":
admid = st.sidebar.text_input("Admin ID")
passw = st.sidebar.text_input("Password",type='password')
if st.sidebar.button("Login"):
result = 1
if result:
user = st.selectbox("Select User",["Admin","Manager","Employee"])
if user == "Admin":
task = st.selectbox("Manage Admin",["View","Add","Delete"])
if task == "View":
st.subheader("Admins")
if task == "Add":
st.subheader("Add admin")
if task == "Delete":
st.subheader("Delete admin")
elif user == "Manager":
task = st.selectbox("Manage Manager",["View","Add","Delete"])
if task == "View":
st.subheader("Managers")
if task == "Add":
st.subheader("Add manager")
if task == "Delete":
st.subheader("Delete manager")
else:
task = st.selectbox("Manage Employee",["View","Add","Delete"])
if task == "View":
st.subheader("Employees")
if task == "Add":
st.subheader("Add employee")
if task == "Delete":
st.subheader("Delete employee")
else:
st.warning("Incorrect Admin ID/Password")
elif choice == "Manager":
manid = st.sidebar.text_input("Manager ID")
passw = st.sidebar.text_input("Password",type='password')
if st.sidebar.button("Login"):
result = 1
if result:
st.success("Logged In as Admin")
else:
st.warning("Incorrect Manager ID/Password")
else:
empid = st.sidebar.text_input("Employee ID")
passw = st.sidebar.text_input("Password",type='password')
if st.sidebar.button("Login"):
result = 1
if result:
st.success("Logged In as Admin")
else:
st.warning("Incorrect Employee ID/Password")
main()
After I run this app and login as admin / manager / employee using sidebar , doing any further action ( using any selectbox ) refreshes the entire app, making the whole app useless. I’ve read many posts that suggest using session state to overcome this problem. But I couldn’t understand how to implement session state. I’ve read about it and watched YouTube videos, still I’m not able to implement it on my own problem. So if anyone could implement any technique to retain all actions for each run on this code, that’d be easy for me to understand session state.
I’ve gone through many Streamlit posts that discuss the same problem, But I couldn’t understand them.