blackary / st_pages

An experimental version of Streamlit Multi-Page Apps
MIT License
467 stars 77 forks source link

Several Issues #67

Closed steelliberty closed 3 months ago

steelliberty commented 1 year ago

Note: I am using the page_switch() module at the same time.

I am getting an error often (not always) that results in the page loading twice due to an exception. The exception is shown below. This happens when using the pages menu in the sidebar. Click back and forth to the various pages repeatedly. cause exceptions. Clicking a subpage will result in the error below, which starts in the current home page called Site_Select.

Traceback (most recent call last): File "/Users/jack/miniconda3/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 541, in _run_script exec(code, module.dict) File "/Users/jack/jmautogpt/masterpro.ai.dashboard/ultimate-flask-front-end-2.1/steamlitapp/pages/2_dashboard.py", line 5, in import Site_Select File "/Users/jack/jmautogpt/masterpro.ai.dashboard/ultimate-flask-front-end-2.1/steamlitapp/Site_Select.py", line 9, in show_pages_from_config(".streamlit/pages.toml") File "/Users/jack/miniconda3/lib/python3.9/site-packages/streamlit/runtime/metrics_util.py", line 367, in wrapped_func result = non_optional_func(*args, *kwargs) File "/Users/jack/miniconda3/lib/python3.9/site-packages/st_pages/init.py", line 295, in _show_pages_from_config show_pages(pages) File "/Users/jack/miniconda3/lib/python3.9/site-packages/streamlit/runtime/metrics_util.py", line 367, in wrapped_func result = non_optional_func(args, kwargs) File "/Users/jack/miniconda3/lib/python3.9/site-packages/st_pages/init.py", line 233, in _show_pages first_page_hash = list(current_pages.keys())[0]** IndexError: list index out of range

If I restart the application and click back and forth between the Home page (Site_Select) and the first subpage I can get this error pop up Cannot read properties of undefined (reading 'pageScriptHash')

There are bugs in this module that take work to find. I can move back and forth from page to page and eventually get the error above. This is a popup error message, and the command line has no stack trace.

Thanks - Jack

blackary commented 1 year ago

Thanks for the stack trace! Could you share an example app that demonstrates this issue?

steelliberty commented 1 year ago

Hi Zachary,

I have this app on my personal machine. I want to help you fix the component or decide if it is your issue or the switch_page module. However, I am considering moving the app to Anvil because I am running into other issues that lead me to believe Steamlit needs to be more robust for my plans.

The UI is weak as a result of the constant page reloads.

I have a Home page (called Site_Select) that is very simple - it fetches some data from an API server and populates a select box. The user selects a "site" (domain name), and then another API call is made to load the primary data for that site.

Then the other pages are used for viewing and editing that data.

I have the pages set up in the toml file as below:

[[pages]] path ="/Users/jackmullen/jmautogpt/masterpro.ai.dashboard/ultimate-flask-front-end-2.1/steamlitapp/Site_Select.py" name = "Select Site" icon = ":arrow_up_small:"

[[pages]] path = "/Users/jackmullen/jmautogpt/masterpro.ai.dashboard/ultimate-flask-front-end-2.1/steamlitapp/pages/2_dashboard.py" name = "Dashboard" icon = ":control_knobs:"

[[pages]] path = "/Users/jackmullen/jmautogpt/masterpro.ai.dashboard/ultimate-flask-front-end-2.1/steamlitapp/pages/3_Manage_Feeds.py" name = "Manage Feeds" icon = ":briefcase:"

[[pages]] name ="WordPress" is_section = true icon = ":open_file_folder:"

[[pages]] path = "/Users/jackmullen/jmautogpt/masterpro.ai.dashboard/ultimate-flask-front-end-2.1/steamlitapp/pages/4_Install_New_Feed.py" name = "Install New Feed" icon = ":new:"

If someone attempts to click on a page that is not initialized, code like this sends them back to the Site_Select page - and sometimes this causes an exception:

jm

import streamlit as st import requests from streamlit_extras.switch_page_button import switch_page from st_pages import add_page_title add_page_title()

load the feeds

def main(): if 'save_feeds_data' not in st.session_state: if "sites" in st.session_state: del st.session_state['sites'] st.info("You Must Select A Site First") if st.button("Continue",key="button1"): switch_page("select site")

else:
    if "sites" in st.session_state:
        col1, col2 = st.columns([3, 3])
        col1.subheader("Sites Under Management")
        col1.data_editor(data=st.session_state.sites,num_rows='dynamic')
        col2.write("Coming Soon Transcription Parameters")

    else:
        st.write("fall through")

if name == "main": main()

In testing just now I got this error message: The page that you have requested does not exist. Running the app's main page. I have to assume that is a problem with the switch_page module, as sometimes it will produce a stack track indicating the page name is not in the list of pages it presents. The only thing I learned there is that it looks for lowercase page names but are the same in the "Name" variable in the toml file. It may be that the primary issue here is that restarting the steamlit server does not clear the state object and old state data is corrupting the program flow. I did not look for a way to clear state data on the first run after a server start. I hope that this helps a little -- I think you can create the environment that will cause the same errors I am seeing.

On Wed, Sep 27, 2023 at 2:08 PM Zachary Blackwood @.***> wrote:

Thanks for the stack trace! Could you share an example app that demonstrates this issue?

— Reply to this email directly, view it on GitHub https://github.com/blackary/st_pages/issues/67#issuecomment-1737859101, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABHAO5XFCIMMVYD6PRJGLBLX4RTTFANCNFSM6AAAAAA5JXRIME . You are receiving this because you authored the thread.Message ID: @.***>

bonfire27 commented 12 months ago

I am getting Cannot read properties of undefined (reading 'pageScriptHash') too. Switching back to version st-pages==0.4.1 solved the issue. My gtihub issue is at: https://github.com/blackary/st_pages/issues/69