I have a scenario in which I would like to change the page title during runtime. My application is this:
I’ve built a rudimentary database which is visualized via st.dataframe. The dataframe contains clickable items. Whenever an item is clicked, a new streamlit page with details about the item is opened. Several arguments are passed to this new details page, e.g. the ID (just an integer) of the clicked item.
One of the users pointed out that it would be really helpful to have the ID displayed in the page title. In case multiple tabs with different items are open, it makes it easier to switch between tabs when the ID of the item is displayed in the page name.
I am aware that I can use this command to configure the page name via:
id is retrieved from either st.session_state or st.query_params.
In order to get the id, I need to run a streamlit command before I can run st.set_page_config. But then st.set_page_config complains that it needs to be the first streamlit command to be executed.
Can I set/change the page_name later in the script? Or is there another way of passing an argument (integer) to the streamlit page and have it included in the page title without the use of streamlit commands?
Btw executing st.session_state or st.query_params as the very first streamlit command (before st.set_page_config) works, but the user is presented with an error message for a split second before the page renders. If possible, I’d like to avoid this.
Your best bet is to use Session State to store the ID or title and set the page title from Session State. You can’t call st.set_page_config after commands that affect three app’s displayed view. Session State is a little exception: you can work with Session State before setting the page configuration.
Here’s an example with dynamic page titles and icons:
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.