With an app that has multiple pages (pages/ directory), the set_page_config(page_icon='my_favicon.ico') only works on the base page. All other pages (everything in pages/) get a streamlit icon or no icon at all (world).
Steps to reproduce
Base page… icon_test1.py
import streamlit as st
st.set_page_config(page_title="Icon Test Main", page_icon='favicon.ico',
layout="wide", menu_items=None)
st.markdown("## Base Page")
pages/1_page1.py:
import streamlit as st
st.markdown("## Page 1")
Run the app and move between the pages and observe the page icon and title in the browser tab.
Expected behavior:
Since we’re not supposed to use set_page_config() more than once in the entire app, I would expect it to apply to all pages, not just the base page.
Actual behavior:
The page_icon displays either a streamlit icon or a “world” on all subpages, title changes to default title on subpages.
Suggested fix would be to either allow the set_page_config() on all pages, or have the settings apply globally.
Debug info
Streamlit version: streamlit-1.21.0
Python version: Python 3.8.12
Using Conda? PipEnv? PyEnv? Pex? No.
OS version: Rocky Linux 8.6 and MacOS 12.3
Browser version: Chrome Version 112.0.5615.49 (Official Build) (arm64)
Requirements file
Just streamlit. I would provide my favicon.ico file, but I don’t see how to upload it.
I tested it with an emoji as well and the last several versions all did this. I took a quick peek on GitHub and I don’t see exactly this issue recorded as an open bug report yet. I believe you can report it as a bug. I agree with your logic that if st.set_page_config is meant to be called first and only once then I would expect the icon to carry over to other pages in the same way layout='wide' does.
I don’t see anything in the documentation st.set_page_config - Streamlit Docs that would indicate that if you use it on one page it carries across multiple pages. As far as I know, the fact that it works with layout=wide is not necessarily an intended behavior. My understanding is that the phrase “and must only be set once” simply applies to a single page, not to an entire multipage app.
That being said, this is certainly a reasonable feature request. But, for now, the easy solution is to call st.set_page_config at the top of each page.
Ah! I see the confusion. The docs say about set_page_config:
This must be the first Streamlit command used in your app, and must only be set once.
This line reads to me on a per app basis rather than a per page basis. My brain made an assumption between that line and the fact that layout carried over that set_page_config was meant as a first line on your app’s main page specifically.
I think a simple edit here along the lines:
This must be the first Streamlit command used on an app page, and must only be set once per page.
Apr 26 10:09:25 weka-beta-os.localdomain start_gui[7213]: Traceback (most recent call last):
Apr 26 10:09:25 weka-beta-os.localdomain start_gui[7213]: File "/opt/gui/venv/lib64/python3.11/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 565, in _run_script
Apr 26 10:09:25 weka-beta-os.localdomain start_gui[7213]: exec(code, module.__dict__)
Apr 26 10:09:25 weka-beta-os.localdomain start_gui[7213]: File "/opt/gui/pages/5_Edit_Hosts_File.py", line 10, in <module>
Apr 26 10:09:25 weka-beta-os.localdomain start_gui[7213]: st.set_page_config(page_title="WEKA Management Station Config", page_icon='favicon.ico',
Apr 26 10:09:25 weka-beta-os.localdomain start_gui[7213]: File "/opt/gui/venv/lib64/python3.11/site-packages/streamlit/runtime/metrics_util.py", line 311, in wrapped_func
Apr 26 10:09:25 weka-beta-os.localdomain start_gui[7213]: result = non_optional_func(*args, **kwargs)
Apr 26 10:09:25 weka-beta-os.localdomain start_gui[7213]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Apr 26 10:09:25 weka-beta-os.localdomain start_gui[7213]: File "/opt/gui/venv/lib64/python3.11/site-packages/streamlit/commands/page_config.py", line 225, in set_page_config
Apr 26 10:09:25 weka-beta-os.localdomain start_gui[7213]: ctx.enqueue(msg)
Apr 26 10:09:25 weka-beta-os.localdomain start_gui[7213]: File "/opt/gui/venv/lib64/python3.11/site-packages/streamlit/runtime/scriptrunner/script_run_context.py", line 90, in enqueue
Apr 26 10:09:25 weka-beta-os.localdomain start_gui[7213]: raise StreamlitAPIException(
Apr 26 10:09:25 weka-beta-os.localdomain start_gui[7213]: streamlit.errors.StreamlitAPIException: `set_page_config()` can only be called once per app, and must be called as the first Streamlit command in your script.
Apr 26 10:09:25 weka-beta-os.localdomain start_gui[7213]: For more information refer to the [docs](https://docs.streamlit.io/library/api-reference/utilities/st.set_page_config).
“set_page_config() can only be called once per app, and must be called as the first Streamlit command in your script.”
@Vince_Fleming Can you share your whole repo? It could be something else you are doing on the 5_edit_hosts_file.py that is also calling st.set_page_config somehow.
It’s a little complicated… I’m using some wheels that I had to make some customizations to, so you would likely have some issues with dependencies. I’ll take some more time to review myself, and if I can’t resolve it, I’ll respond here with the github link.
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.