I don’t want to use the magic commands, I’ll rather stick to the st.write convention.
So my question is as follows: is it possible to put the Streamlit elements inside these partials and then import the partials in the subpage, in order to have the subpage code less complex?
If yes, could you address me to a guide on how to realize it? My attempt at doing this with import statements didn’t work.
Just to clarify, is the main motivation for splitting up the pages into multiple files just to keep the files shorter? Or is there something else you’re trying to accomplish?
I would like this as well. It is much cleaner to manage an authentication page if I were able to do something like this:
import os
import streamlit as st
from streamlit_cookies_manager import EncryptedCookieManager
from dotenv import load_dotenv
from auth import authenticate
from partials import landing, login_form, register_form
# API Base URL
api_base_url = st.secrets["API_BASE_URL"]
# Create a cookie manager instance
cookie_manager = EncryptedCookieManager(
prefix=st.secrets["COOKIE_MANAGER_PREFIX"],
password=st.secrets["COOKIE_MANAGER_PASSWORD"]
)
def main():
# Wait for the component to load and send us current cookies.
if not cookie_manager.ready():
st.stop()
# Check if the user is already authenticated
access_token = cookie_manager.get("access_token")
st.header("AI Toolbox")
if access_token:
st.session_state["access_token"] = access_token
landing()
else:
login_tab, register_tab = st.tabs(["Login", "Register"])
with login_tab:
access_token = login_form()
if access_token:
# Store the access token in a cookie
cookie_manager.set("access_token", access_token)
st.rerun()
else:
st.warning("Invalid credentials. Please try again.")
with register_tab:
access_token = register_form()
if access_token:
# Store the access token in a cookie
cookie_manager.set("access_token", access_token)
st.rerun()
else:
st.warning("Unable to authenticate. Please try again.")
if __name__ == "__main__":
load_dotenv()
main()
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.