Hello, having problems with including multiple buttons in my app. I initially have a login button that authenticates users into the app, and then I would like to perform more functions for users that are logged in, however, when I click a button after the login, the app does not run correctly, and won’t let me include more into the app. Below is my code. Not sure if it has anything to do with the session states, or how can I get more functions that include buttons to work following the login button?
import streamlit as st
import pandas as pd
import yaml
import bcrypt
def load_users(filename):
with open(filename, 'r') as file:
return yaml.safe_load(file)
def authenticate(username, password):
for user in users:
if user['username'] == username and bcrypt.checkpw(password.encode('utf-8'), user['password'].encode('utf-8')):
return True
return False
users_data = load_users('myusers.yaml')
users = users_data['users']
username = st.text_input("Username")
password = st.text_input("Password", type="password")
if st.button("Login"):
if authenticate(username, password):
st.success("Login successful!")
st.write(f"Welcome, {username}!")
st.subheader("")
st.header("Instructions")
st.subheader("...Once human interface is chosen, and instructions are clear on how to use device, enter instructions here...")
st.header("")
if "button_clicked" not in st.session_state:
st.session_state.button_clicked = False
def begin_callback():
# "Yes" button was clicked
st.session_state.button_clicked = True
def no_callback():
# "No" button was clicked
alert = st.warning("Please go back to the main page")
#time.sleep(3)
#alert.empty()
def yes_callback():
st.balloons()
st.title("Your data collection has begun")
st.session_state.button_clicked = False
st.subheader("Would you like to begin data collection?")
if not st.session_state.button_clicked:
st.button("Click Here to Begin Data Collection", on_click=begin_callback)
else:
st.button("Yes", on_click=yes_callback)
st.button("No", on_click=no_callback)
else:
st.error("Invalid username or password.")