4

I have made separate functions for each page, but i want to change page to file upload when I click button on welcome_page.py. Found a switch_page function but I don't think I understand how it works.

import streamlit as st
from login import check_password
from file_upload import file_upload
from welcome import welcome_page
from PIL import Image
from numpy import asarray
from streamlit_extras.switch_page_button import switch_page

def file_upload():
    datafile = st.file_uploader("Upload JPG",type=['jpg'])
    if datafile is not None:
        numpydata = asarray(datafile)
        print(type(numpydata))
        st.image(datafile)
        return True
    
    return False

if check_password():
    if welcome_page():
        switch_page('file_upload')
        fileDetails = file_upload()
        if fileDetails:
            print("file uploaded")

2 Answers 2

2

Unfortunately, there isn't a built-in way to switch pages programmatically in a Streamlit multipage app. There is an open feature request here if you'd like to upvote it.

Sign up to request clarification or add additional context in comments.

Comments

0

There is a way out

in your main app.py, define all pages using

pg = st.navigation([st.Page("Page1"),st.Page("Page2"),st.Page("file_upload"),st.Page("welcome_page"),st.Page("Pagex"),st.Page("Pagey"),st.Page("Pagez")])
pg.run()

in welcome_page.py

if st.button("Welcome Page Button that redirects to file upload page"):
    pg = st.navigation([st.Page("file_upload")])
    pg.run()
    # this will navigate to file_upload page

Make sure to keep the same page name "file_upload" in both the .py files

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.