Source Code: github.com/Ashwani132003/pondering/blob/main/main.py Get Icons here: icons.getbootstrap.com/ Ask your doubts below and chekout other streamlit tutorials from playlist. Thanks
If you don't want to hold the values, then you don't need to use session state, but if if you still want to use it for something, then you will have to change them on each page like st.session_state.variable = '' or whatever accc. to your variable value. (Ideal approach would be to reset all at once, there is something mentioned for using st.experimental_query_params too for this, but those doesn't seem to work for me, you van give that a try too), thanks
Great work . But do you have any idea of navigating tabs using button or hyperlink? Eg. if I want to go from about tab to home tab by clicking on button. I
For navigating there is an official way of page link in streamlit: docs.streamlit.io/develop/api-reference/widgets/st.page_link But this method works only when we have multipages inside Pages folder (multipage website using the official way not the one in video), you can either run the content of that page /home in account on button click or try to figure a diff. way else use the official/pages folder method for creating multipage website. Both ways have advantages, disadvantages, use the one acc. to your use. Hope it helps, thanks
I have an error where it tells me to define the files. E.g 'home' is not defined in home.app(). How do i fix this. I have a file called home.py in the same folder
Have you correctly imported home in the file(main.py) where you are getting this error? If possible drop a screenshot in our discord channel, would be easier to debug for me, thanks
All other menus run perfectly well with the main except Account which continually throws this exceptionTypeError: app() missing 1 required positional argument: 'choice' . Note Account itself runs okay when creating an account and login. Kindly assist
Hi there, I think in your account.py file when you are doing app() in the if __name__ part or inside the main.py where you are running app() for account page, you are not passing the choice parameter, which i think you have used while creating def app(choice) method, not sure if you used that from my other videos but if your app function inside account.py requires a choice parameter then please pass it where you are calling that function, or maybe use a default one for specific use case, I hope you got the reason for the error, if you still have any doubt feel free to ask here or on our discord server, thanks!
Yes it's completely fine, could be more helpful in some cases, for some cases the one where pages folder is created could be useful. It would give you more customised way then the default way.
@@Dexxx-ff oh, yes you can definitely use it, btw I was talking about the syntax to create multi-page website, As for the project it's public you can use it accordingly.
Yes, we can do that, here is a sample code from chatgpt, i hadn't tried it but what its doing is simply creating other pages after succesfull login only, this is one way, you can import the login function from account.py(login file) also or simply add this kind of syntax for multi page inside your login/signup file itself. You can change the login logic with the one i showed in streamlit playlist videos. Ask me if you get stuck somewhere.Thanks Code: import streamlit as st from streamlit_option_menu import option_menu import home, trending, test, your, about st.set_page_config( page_title="Pondering", ) class MultiApp: def __init__(self): self.apps = [] self.logged_in = False # Track login status def add_app(self, title, func): self.apps.append({ "title": title, "function": func }) def login(self, username, password): # Implement your login logic here # Check if the username and password are valid # For example, you can use a dictionary or a database to validate valid_users = { "user1": "password1", "user2": "password2", } if username in valid_users and password == valid_users[username]: self.logged_in = True return True else: return False def run(self): if not self.logged_in: # Display the login form if not logged in username = st.sidebar.text_input("Username") password = st.sidebar.text_input("Password", type="password") if st.sidebar.button("Login"): if self.login(username, password): st.sidebar.success("Login successful") else: st.sidebar.error("Invalid username or password") if self.logged_in: # If logged in, display navigation options with st.sidebar: app = option_menu( menu_title='Pondering', options=['Home', 'Trending', 'Your Posts', 'about'], icons=['house-fill', 'trophy-fill', 'chat-fill', 'info-circle-fill'], menu_icon='chat-text-fill', default_index=0, styles={ "container": {"padding": "5!important", "background-color": 'black'}, "icon": {"color": "white", "font-size": "23px"}, "nav-link": {"color": "white", "font-size": "20px", "text-align": "left", "margin": "0px", "--hover-color": "blue"}, "nav-link-selected": {"background-color": "#02ab21"}, } ) if app == "Home": home.app() if app == "Trending": trending.app() if app == 'Your Posts': your.app() if app == 'about': about.app() # Create an instance of MultiApp multi_app = MultiApp() # Define your Streamlit apps multi_app.add_app("Home", home.app) multi_app.add_app("Trending", trending.app) multi_app.add_app("Your Posts", your.app) multi_app.add_app("about", about.app) # Run the MultiApp multi_app.run()
@@beginnerscodezone can we have the option that if different users log in the program will display different menu items,? user 1 only have a home and account while user 2 will show all the option in the menu
@@BestRestaurantToEat Case 1: here, to run the pages you can have a st.session_state.check=False and when user logins, set it to true. and something like: if app == "Home": home.app() if app == "Account" and st.session_state.check == True: account.app() Case2: And for not even showing the option you can set the conditions at sidebar itself, say home, account are page you want to show to all users, then just add these 2 in options, after that do condition check and if it matches then rewrite the sidebar thing with all that options. Something like this, # In account page maybe if st.button("Login"): user_logged_in = True # in main.py if user_logged_in: app = st.selectbox( label='app', options=['Home', 'Account', 'History', 'About'], index=1 ) if app == "Home": home.app() elif app == "Account": account.app() elif app == 'History': your.app() elif app == 'About': about.app() else: app = st.selectbox( label='app', options=['Home', 'About'], index=0 ) if app == "Home": home.app() elif app == 'About': about.app()
Hey, thanks for the code. very helpful. The code that you're providing in the comments, the logon page is first, it runs and brings the login page asks for username and password ones you write the username and password it says invalid password or username. what is the solution for it? thanks again!!
if you could provide me the whole code for signup page and the multipage together that is in the video that will be perfect. thanks for replying though!.
@@khadijasediqi9667 hey code link is available in the description and for sign-up page is same you have to select the signup option from selectbox on website's account page. Thanks
@@beginnerscodezone what you mean by selectbox? in the code inside the account page? if that is where you're addressing in the video the code for account is #import streamlit as st #def app(): # st.write('account')
Yeah you can add these files into 'pages' (or some other folder) and can access them by providing correct file path.But it's not compulsory to do that way, if you prefer that way, then you can do it like that, both methods works fine. It doesn't have anything related to syntax of multipages in streamlit, it's just a convenient way of storing all pages files into a single folder.
If my Streamlit application is too slow, I consider adding separate pages to divide the workload. Will the approach I take work well and meet expectations, namely dividing the workload?@@beginnerscodezone
@@rendikanurhartantos.7940 Dividing in multiple pages could help if you don't need to do all operations at a time, I would suggest you to use session state/cache in streamlit also for performing an operation single time and use its outcomes directly when applicable, so you won't be running the whole function again and again unless required. Thanks
Having looked into that recently, one inconvenient using the native "pages" functionality is that if you use login/authentication, there is currently no way to hide that "pages" menu from visitors not yet logged in, which is not good at all. With this option menu you have control on what you can show.
Hey, I am unable to clearly understand what you are asking, but I think you are asking about the default page loading when we first run our website, you can choose whichever page you like to load initially by changing the default index value to the index of page you want to load(from options). Sorry if I misunderstood something, you can ask it again if that's the case. Thanks
@@beginnerscodezone I expressed myself poorly. I would like to understand what a login page would look like that unlocks all pages and takes you to the home page.
@@warlockalpha for unlocking, I think you want to give a specific page access to specific users only that you can check with their user ids , you can add the command to directly open home page after successful login code i.e home.app() . Or you can just add some button that says go to home page like that. Similarly if you want to lock the pages for unauthorised users, you can simply check the userid whenever a person clicks that page and if he is not logged in or is not authorised then just show an error message instead of calling app() method of that page. Is it what you are asking? Also for checking conditions you can refer the code for f() method inside test.py or login.py file in the code. Thanks
Just what I was looking for. You make it simple and easy. Great work!
Source Code:
github.com/Ashwani132003/pondering/blob/main/main.py
Get Icons here: icons.getbootstrap.com/
Ask your doubts below and chekout other streamlit tutorials from playlist. Thanks
Well done. Continue your work!
thanks, good tips sharing
broooo luv you u are so underrated
Perfectoooo!! tx very much!
Great example thank you
Just a question here, how to reset session.state when moving from one page to another as it is holding the value of variable even we change page
If you don't want to hold the values, then you don't need to use session state, but if if you still want to use it for something, then you will have to change them on each page like st.session_state.variable = '' or whatever accc. to your variable value. (Ideal approach would be to reset all at once, there is something mentioned for using st.experimental_query_params too for this, but those doesn't seem to work for me, you van give that a try too), thanks
Very helpful. Thank you!
I'm Glad to know that, it's helpful you!!
Great work . But do you have any idea of navigating tabs using button or hyperlink? Eg. if I want to go from about tab to home tab by clicking on button. I
For navigating there is an official way of page link in streamlit: docs.streamlit.io/develop/api-reference/widgets/st.page_link
But this method works only when we have multipages inside Pages folder (multipage website using the official way not the one in video), you can either run the content of that page /home in account on button click or try to figure a diff. way else use the official/pages folder method for creating multipage website.
Both ways have advantages, disadvantages, use the one acc. to your use.
Hope it helps, thanks
I have an error where it tells me to define the files. E.g 'home' is not defined in home.app(). How do i fix this. I have a file called home.py in the same folder
Have you correctly imported home in the file(main.py) where you are getting this error? If possible drop a screenshot in our discord channel, would be easier to debug for me, thanks
Grate masallah
All other menus run perfectly well with the main except Account which continually throws this exceptionTypeError: app() missing 1 required positional argument: 'choice' . Note Account itself runs okay when creating an account and login. Kindly assist
Hi there, I think in your account.py file when you are doing app() in the if __name__ part or inside the main.py where you are running app() for account page, you are not passing the choice parameter, which i think you have used while creating def app(choice) method, not sure if you used that from my other videos but if your app function inside account.py requires a choice parameter then please pass it where you are calling that function, or maybe use a default one for specific use case,
I hope you got the reason for the error, if you still have any doubt feel free to ask here or on our discord server, thanks!
Thanks! I don´t like the practice implemented in the oficial documentation of multipages. This is great!
Thank you so much😢
Thanks
I have really tried to resolve it but same error kept throwing up.Kindly assist me to enable me complete my project.
Hey, drop a message in our discord server, would be easier to help you there, thanks
Is it ok use this multipage code to create a streamlit website ??
Yes it's completely fine, could be more helpful in some cases, for some cases the one where pages folder is created could be useful. It would give you more customised way then the default way.
@@beginnerscodezone can I modify it a bit and make streamlit webpage , there will be not palagrism issue right?
@@Dexxx-ff oh, yes you can definitely use it, btw I was talking about the syntax to create multi-page website,
As for the project it's public you can use it accordingly.
Hi, I wonder if I can first get in the login page without the menu. After successfully login then the menu show for navigation? Thank you.
Yes, we can do that, here is a sample code from chatgpt, i hadn't tried it but what its doing is simply creating other pages after succesfull login only, this is one way, you can import the login function from account.py(login file) also or simply add this kind of syntax for multi page inside your login/signup file itself.
You can change the login logic with the one i showed in streamlit playlist videos.
Ask me if you get stuck somewhere.Thanks
Code:
import streamlit as st
from streamlit_option_menu import option_menu
import home, trending, test, your, about
st.set_page_config(
page_title="Pondering",
)
class MultiApp:
def __init__(self):
self.apps = []
self.logged_in = False # Track login status
def add_app(self, title, func):
self.apps.append({
"title": title,
"function": func
})
def login(self, username, password):
# Implement your login logic here
# Check if the username and password are valid
# For example, you can use a dictionary or a database to validate
valid_users = {
"user1": "password1",
"user2": "password2",
}
if username in valid_users and password == valid_users[username]:
self.logged_in = True
return True
else:
return False
def run(self):
if not self.logged_in:
# Display the login form if not logged in
username = st.sidebar.text_input("Username")
password = st.sidebar.text_input("Password", type="password")
if st.sidebar.button("Login"):
if self.login(username, password):
st.sidebar.success("Login successful")
else:
st.sidebar.error("Invalid username or password")
if self.logged_in:
# If logged in, display navigation options
with st.sidebar:
app = option_menu(
menu_title='Pondering',
options=['Home', 'Trending', 'Your Posts', 'about'],
icons=['house-fill', 'trophy-fill', 'chat-fill', 'info-circle-fill'],
menu_icon='chat-text-fill',
default_index=0,
styles={
"container": {"padding": "5!important", "background-color": 'black'},
"icon": {"color": "white", "font-size": "23px"},
"nav-link": {"color": "white", "font-size": "20px", "text-align": "left", "margin": "0px",
"--hover-color": "blue"},
"nav-link-selected": {"background-color": "#02ab21"},
}
)
if app == "Home":
home.app()
if app == "Trending":
trending.app()
if app == 'Your Posts':
your.app()
if app == 'about':
about.app()
# Create an instance of MultiApp
multi_app = MultiApp()
# Define your Streamlit apps
multi_app.add_app("Home", home.app)
multi_app.add_app("Trending", trending.app)
multi_app.add_app("Your Posts", your.app)
multi_app.add_app("about", about.app)
# Run the MultiApp
multi_app.run()
@@beginnerscodezone Thank you! I will have a try.
@@beginnerscodezone can we have the option that if different users log in the program will display different menu items,? user 1 only have a home and account while user 2 will show all the option in the menu
@@BestRestaurantToEat
Case 1: here, to run the pages you can have a st.session_state.check=False and when user logins, set it to true.
and something like:
if app == "Home":
home.app()
if app == "Account" and st.session_state.check == True:
account.app()
Case2: And for not even showing the option you can set the conditions at sidebar itself,
say home, account are page you want to show to all users, then just add these 2 in options,
after that do condition check and if it matches then rewrite the sidebar thing with all that options. Something like this,
# In account page maybe
if st.button("Login"):
user_logged_in = True
# in main.py
if user_logged_in:
app = st.selectbox(
label='app',
options=['Home', 'Account', 'History', 'About'],
index=1
)
if app == "Home":
home.app()
elif app == "Account":
account.app()
elif app == 'History':
your.app()
elif app == 'About':
about.app()
else:
app = st.selectbox(
label='app',
options=['Home', 'About'],
index=0
)
if app == "Home":
home.app()
elif app == 'About':
about.app()
@@beginnerscodezone Tqvm
Mam which python version your are using
Hey, I mainly use python version 3.10, sometimes I have to use 3.9 also for some libraries.
madam is it possible to connect html files and streamlit
Yes, you can refer: discuss.streamlit.io/t/include-an-existing-html-file-in-streamlit-app/5655
Hey, thanks for the code. very helpful. The code that you're providing in the comments, the logon page is first, it runs and brings the login page asks for username and password ones you write the username and password it says invalid password or username. what is the solution for it? thanks again!!
Thanks, you first have to signup and then use that username and password.
I run the code it provides me with a login page, there was no sign-up page.
if you could provide me the whole code for signup page and the multipage together that is in the video that will be perfect. thanks for replying though!.
@@khadijasediqi9667 hey code link is available in the description and for sign-up page is same you have to select the signup option from selectbox on website's account page. Thanks
@@beginnerscodezone what you mean by selectbox? in the code inside the account page? if that is where you're addressing in the video the code for account is #import streamlit as st
#def app():
# st.write('account')
In my system streamlit does not install.please help.i try a lot
Please drop a message in our discord channel with an error screenshot if applicable, thanks
Why don't you us the 'pages' folder as they say to do in streamlit ?
Yeah you can add these files into 'pages' (or some other folder) and can access them by providing correct file path.But it's not compulsory to do that way, if you prefer that way, then you can do it like that, both methods works fine. It doesn't have anything related to syntax of multipages in streamlit, it's just a convenient way of storing all pages files into a single folder.
If my Streamlit application is too slow, I consider adding separate pages to divide the workload. Will the approach I take work well and meet expectations, namely dividing the workload?@@beginnerscodezone
@@rendikanurhartantos.7940 Dividing in multiple pages could help if you don't need to do all operations at a time, I would suggest you to use session state/cache in streamlit also for performing an operation single time and use its outcomes directly when applicable, so you won't be running the whole function again and again unless required. Thanks
Having looked into that recently, one inconvenient using the native "pages" functionality is that if you use login/authentication, there is currently no way to hide that "pages" menu from visitors not yet logged in, which is not good at all.
With this option menu you have control on what you can show.
where do we get the icons?
Get Icons from here: icons.getbootstrap.com/
Thanks!
Hi. I'm Like you.
Do you can create login page to live the other pages?
Hey, I am unable to clearly understand what you are asking, but I think you are asking about the default page loading when we first run our website, you can choose whichever page you like to load initially by changing the default index value to the index of page you want to load(from options).
Sorry if I misunderstood something, you can ask it again if that's the case. Thanks
@@beginnerscodezone I expressed myself poorly.
I would like to understand what a login page would look like that unlocks all pages and takes you to the home page.
@@warlockalpha for unlocking, I think you want to give a specific page access to specific users only that you can check with their user ids , you can add the command to directly open home page after successful login code i.e home.app() . Or you can just add some button that says go to home page like that.
Similarly if you want to lock the pages for unauthorised users, you can simply check the userid whenever a person clicks that page and if he is not logged in or is not authorised then just show an error message instead of calling app() method of that page.
Is it what you are asking?
Also for checking conditions you can refer the code for f() method inside test.py or login.py file in the code.
Thanks
For icons website name ?
Here you go: icons.getbootstrap.com/