Create Multi Pages websites using Streamlit | Python

Поделиться
HTML-код
  • Опубликовано: 29 авг 2024

Комментарии • 62

  • @pdamartin4203
    @pdamartin4203 10 месяцев назад +3

    Just what I was looking for. You make it simple and easy. Great work!

  • @beginnerscodezone
    @beginnerscodezone  Год назад +6

    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

  • @jitvimol
    @jitvimol 10 месяцев назад

    Well done. Continue your work!

  • @letuan930
    @letuan930 9 месяцев назад

    thanks, good tips sharing

  • @M12sGaming15821
    @M12sGaming15821 5 месяцев назад

    broooo luv you u are so underrated

  • @DanielVen-fy7or
    @DanielVen-fy7or 5 месяцев назад

    Perfectoooo!! tx very much!

  • @sharafwada1940
    @sharafwada1940 10 месяцев назад

    Great example thank you

  • @manish18ya
    @manish18ya Месяц назад

    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

    • @beginnerscodezone
      @beginnerscodezone  Месяц назад

      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

  • @tosinlitics949
    @tosinlitics949 Год назад

    Very helpful. Thank you!

  • @soeyuyjj2533
    @soeyuyjj2533 3 месяца назад

    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

    • @beginnerscodezone
      @beginnerscodezone  3 месяца назад

      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

  • @yesiam6051
    @yesiam6051 Месяц назад

    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

    • @beginnerscodezone
      @beginnerscodezone  Месяц назад

      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

  • @waleedpindi9304
    @waleedpindi9304 10 месяцев назад

    Grate masallah

  • @royalclassicengineering7609
    @royalclassicengineering7609 3 месяца назад

    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

    • @beginnerscodezone
      @beginnerscodezone  3 месяца назад +2

      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!

  • @xjuliodiaz888
    @xjuliodiaz888 9 месяцев назад

    Thanks! I don´t like the practice implemented in the oficial documentation of multipages. This is great!

  • @magnolia7799
    @magnolia7799 6 месяцев назад

    Thank you so much😢

  • @tecnom7133
    @tecnom7133 4 месяца назад

    Thanks

  • @royalclassicengineering7609
    @royalclassicengineering7609 3 месяца назад

    I have really tried to resolve it but same error kept throwing up.Kindly assist me to enable me complete my project.

    • @beginnerscodezone
      @beginnerscodezone  3 месяца назад

      Hey, drop a message in our discord server, would be easier to help you there, thanks

  • @Dexxx-ff
    @Dexxx-ff 4 месяца назад

    Is it ok use this multipage code to create a streamlit website ??

    • @beginnerscodezone
      @beginnerscodezone  4 месяца назад

      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
      @Dexxx-ff 4 месяца назад

      @@beginnerscodezone can I modify it a bit and make streamlit webpage , there will be not palagrism issue right?

    • @beginnerscodezone
      @beginnerscodezone  4 месяца назад +1

      @@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.

  • @kororinpakevin239
    @kororinpakevin239 10 месяцев назад

    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.

    • @beginnerscodezone
      @beginnerscodezone  10 месяцев назад +1

      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()

    • @kororinpakevin239
      @kororinpakevin239 10 месяцев назад

      @@beginnerscodezone Thank you! I will have a try.

    • @BestRestaurantToEat
      @BestRestaurantToEat 8 месяцев назад +1

      @@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

    • @beginnerscodezone
      @beginnerscodezone  8 месяцев назад

      ​@@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()

    • @BestRestaurantToEat
      @BestRestaurantToEat 8 месяцев назад

      @@beginnerscodezone Tqvm

  • @Positivevibes-b4u
    @Positivevibes-b4u 9 месяцев назад

    Mam which python version your are using

    • @beginnerscodezone
      @beginnerscodezone  9 месяцев назад

      Hey, I mainly use python version 3.10, sometimes I have to use 3.9 also for some libraries.

  • @varaprasad-yw1lk
    @varaprasad-yw1lk 5 месяцев назад

    madam is it possible to connect html files and streamlit

    • @beginnerscodezone
      @beginnerscodezone  5 месяцев назад

      Yes, you can refer: discuss.streamlit.io/t/include-an-existing-html-file-in-streamlit-app/5655

  • @khadijasediqi9667
    @khadijasediqi9667 8 месяцев назад

    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!!

    • @beginnerscodezone
      @beginnerscodezone  8 месяцев назад

      Thanks, you first have to signup and then use that username and password.

    • @khadijasediqi9667
      @khadijasediqi9667 8 месяцев назад

      I run the code it provides me with a login page, there was no sign-up page.

    • @khadijasediqi9667
      @khadijasediqi9667 8 месяцев назад

      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!.

    • @beginnerscodezone
      @beginnerscodezone  8 месяцев назад

      @@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

    • @khadijasediqi9667
      @khadijasediqi9667 8 месяцев назад

      @@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')

  • @ChandanKumar-mw7oc
    @ChandanKumar-mw7oc 5 месяцев назад

    In my system streamlit does not install.please help.i try a lot

    • @beginnerscodezone
      @beginnerscodezone  4 месяца назад

      Please drop a message in our discord channel with an error screenshot if applicable, thanks

  • @Josvani3
    @Josvani3 10 месяцев назад

    Why don't you us the 'pages' folder as they say to do in streamlit ?

    • @beginnerscodezone
      @beginnerscodezone  10 месяцев назад +2

      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.

    • @rendikanurhartantos.7940
      @rendikanurhartantos.7940 7 месяцев назад

      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

    • @beginnerscodezone
      @beginnerscodezone  7 месяцев назад

      @@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

    • @quarkinjapan
      @quarkinjapan 6 месяцев назад

      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.

  • @nithinv791
    @nithinv791 5 месяцев назад

    where do we get the icons?

    • @beginnerscodezone
      @beginnerscodezone  5 месяцев назад

      Get Icons from here: icons.getbootstrap.com/
      Thanks!

  • @warlockalpha
    @warlockalpha 11 месяцев назад

    Hi. I'm Like you.
    Do you can create login page to live the other pages?

    • @beginnerscodezone
      @beginnerscodezone  11 месяцев назад

      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

    • @warlockalpha
      @warlockalpha 11 месяцев назад

      @@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.

    • @beginnerscodezone
      @beginnerscodezone  11 месяцев назад

      @@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

  • @YASH-rs3zn
    @YASH-rs3zn 10 месяцев назад

    For icons website name ?