Trick - Simple MultPage

Hi Guys !
Here a simple examplehow to create a simple multpage !
Organize your python files as you wish !

In this example I used option menu, but you can use radio button or other else !

Take a look at the example structure:
image

import streamlit as st 
from streamlit_option_menu import option_menu
from views import home, login, userinfo


v_menu=["Home", "Login", "User Info"]

with st.sidebar:

    st.header("MULTPAGE WITH OPTION MENU")

    selected = option_menu(
        menu_title=None,  # required
        options=v_menu,  # required
        icons=None,  # optional
        menu_icon="menu-down",  # optional
        default_index=0,  # optional
    )

if selected=="Home":
    home.createPage()

if selected=="Login":
    login.createPage()

if selected=="User Info":
    userinfo.createPage()

That simple !
The trick is where you put the streamlit´s elements
See it !

5 Likes

Nice solution for simple multi-page.

FYI - I wrote a tiny framework for flexible menus/sub-menus which keeps the menu definitions all in one place. See this reply in the OP’s thread about option menu.

Thanks @asehmi
I will gonna see it !

1 Like

Thanks for sharing @ricardo.pascoal .
I received an AttributeError: module ‘pages.{page_name}’ has no attribute ‘createPage’. From where is the createPage function coming from ?

Thanks in advance.

Hi @miro
Well, you need to create this function for each python file home.py, login.py, userinfo.py
Do the someting for all files…ok

thank you for that @ricardo.pascoal, yes it all works. Is there a way that we can actually leverage the new Streamlit 1.10 Multi-Page functionality where each page has a unique URL?

I´m not a better person to answer you.
I´m testing Streamlit yet, at moment I dont have this need.