简体   繁体   中英

How to switch page on button click using Streamlit?

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM