While testing locally my project(testing) using subprocess function to open/ run another page('run streamlit.page.py), it is working correctly. But when deploying it on streamlit, it not taking any action when clicking on the button.
Another test i did at deployment stage, trying to create as if a login page before accessing the analytical page, After inserting the credentials, when clicking on the log in button, not action is being taken. When it worked perfectly on localhost.
Could you please try to bring all your code under one roof by ditching the subprocess module and pulling the code from your other script into your main Streamlit app?
So while Streamlit does not provide built-in support for user authentication, you can still create a simple login interface within your app. Here’s a very basic way of doing this:
import streamlit as st
def main():
st.write("Welcome to the main application") # This is the main application code
def check_password(stored_password, user_password):
if stored_password == user_password:
return True
else:
return False
def password_input():
st.subheader("Login to the application")
username = st.text_input("User Name")
password = st.text_input("Password", type='password')
return username, password
def login():
username, password = password_input()
if st.button("Login"):
stored_password = "your_password" # You can encrypt this password or store it securely somewhere
if check_password(stored_password, password):
st.write(f"Logged in as {username}")
main()
else:
st.error("The password you entered is incorrect")
login()
But i issue is becoming when i deploy it; after clicking on the log in button no action is been taken to redirect me toward the main page. So, the issue is the load of new page (run of another py code). Else the other time would be working fine.
Can you help please? Like a sample would have help; as with a log in that will redirect to a page that have multiple pages.
It’s a bit difficult to diagnose and advise without any benchmarked code, but as an alternative, here’s a simple function I created for my internal needs to apply a login to every single page of an MPA app.
import streamlit as st
# Hardcoded password
correct_password = "one"
def check_password():
"""Returns `True` if the user has the correct password."""
# Initialize 'password_correct' if it's not in the session state
if "password_correct" not in st.session_state:
st.session_state["password_correct"] = False
# If the password has already been entered correctly, don't ask again
if st.session_state.password_correct:
return True
# Initialize 'password' if it's not in the session state
if "password" not in st.session_state:
st.session_state["password"] = ""
def password_entered():
"""Checks whether a password entered by the user is correct."""
if st.session_state.password == correct_password:
st.session_state.password_correct = True
else:
st.session_state.password_correct = False
# If the password is not correct, show input + error.
st.text_input(
"Please authenticate to access the pages",
type="password",
on_change=password_entered,
key="password",
)
if st.session_state.password_correct:
return True
elif st.session_state.password:
st.error("😕 Password incorrect")
return False
You would then call this on every page, this way, at the top of each page.
from password import check_password
if check_password():
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.