streamlit-extras
streamlit-extras copied to clipboard
🐛 [BUG] - Hardcoded main script path in switch_page_button extra
Description
The main script path is hardcoded in switch_page_button/__init__.py
It will always lead to a
RerunException
if the main script is renamed. Page switching still works, however the expection raising can lead to problems in error handling. For example it will not work if the switch_page
method is part of a try/except block.
I already have a proposal to fix this and I'd love to contribute, however I'm not sure how to create a pull request 😄
Reproduction steps
1. Rename script
2. wrap switch_page in try/except block
3. Press switch page button
4. Nothing will happen
Version of streamlit
1.30.0
Version of streamlit-extras
0.4.0
Thanks @ivaniliash - would adding a main_module_filename: str = "streamlit_app.py"
as a parameter to the switch_page
function solve your issue?
@arnaudmiribel I simply replaced line 22 with pages = get_pages(os.path.basename(__main__.__file__))
. Should work if its always the main script we are looking for.
Edit: Probably os.path.basename
is not needed though, but not sure
Closing this as switch_page
is now a native command in Streamlit!