blackary / st_pages

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

Streamlit 1.36.0 breaks functionality #99

Closed danb27 closed 4 months ago

danb27 commented 4 months ago

To reproduce:

# ui.py
from st_pages import Page, show_pages

pages = [
    Page("ui.py", "home"),
    Page("page.py", "page"),
]
show_pages(pages)
# page.py
import streamlit as st

st.title("hi")
# requirements.txt
streamlit==1.36.0
st_pages==0.4.5

streamlit run ui.py

Results in exception:

AttributeError: 'str' object has no attribute 'main_script_path'
Traceback:
File "/Users/dan/repos/scrap/foo/.venv/lib/python3.11/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 589, in _run_script
    exec(code, module.__dict__)
File "/Users/dan/repos/scrap/foo/src/ui.py", line 7, in <module>
    show_pages(pages)
File "/Users/dan/repos/scrap/foo/.venv/lib/python3.11/site-packages/streamlit/runtime/metrics_util.py", line 408, in wrapped_func
    result = non_optional_func(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/dan/repos/scrap/foo/.venv/lib/python3.11/site-packages/st_pages/__init__.py", line 252, in _show_pages
    rt._sources_watcher = LocalSourcesWatcher(rt._main_script_path)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/dan/repos/scrap/foo/.venv/lib/python3.11/site-packages/streamlit/watcher/local_sources_watcher.py", line 51, in __init__
    self._main_script_path = os.path.abspath(self._pages_manager.main_script_path)
                                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Temporary fix is to set streamlit<1.36.0 in your application

george-gca commented 4 months ago

Just found out that Streamlit 1.36.0 introduced st.navigation and st.Page. Maybe now Streamlit officially supports this feature and this 3rd party is not necessary anymore?

danb27 commented 4 months ago

Just found out that Streamlit 1.36.0 introduced st.navigation and st.Page. Maybe now Streamlit officially supports this feature and this 3rd party is not necessary anymore?

Ooo interesting. I was just focused on fixing my build.

andrew-weisman commented 4 months ago

FWIW, I'm still interested in solving this within st_pages because the new functionality mentioned by @george-gca does not allow for multiprocessing to be run in the app (as far as I can tell).

@blackary, any ideas? Thanks in advance!

HoangNguyen689 commented 4 months ago

I am still facing this problem with show_pages_from_config(). Do you fix that in v0.5.0?

blackary commented 4 months ago

Yes, this should be fixed by release 0.5.0

andrew-weisman commented 3 months ago

Confirmed that 0.5.0 fixes the problem. Thanks so much @blackary!