Brief summary of my code… user authentication is applied such that with the correct login, then new questions are asked, but I need multiple buttons after the login, and those are interfering with the login button.
Can you provide a context such as SS or code repo what you are trying to achieve?
import streamlit as st
import pandas as pd
import yaml
import bcrypt
st.subheader(“Please login with your username and password below”)
st.markdown(“”)
Function to load users from the YAML file
def load_users(filename):
with open(filename, ‘r’) as file:
return yaml.safe_load(file)
Function to authenticate user
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
Load users from the YAML file
users_data = load_users(‘myusers.yaml’)
users = users_data[‘users’]
Input fields for username and password
username = st.text_input(“Username”)
password = st.text_input(“Password”, type=“password”)
Login button
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.”)
This is the code that I am using, when I click the data collection buttons, the function doesn’t go through and takes me back to the login button.
I am wondering how I can have both buttons under the login button, to still function correctly, without interfering with the login button.