streamlit / streamlit

Streamlit — A faster way to build and share data apps.
https://streamlit.io
Apache License 2.0
35.14k stars 3.05k forks source link

Change page title & favicon after first st call #2216

Open stonier opened 4 years ago

stonier commented 4 years ago

Problem

Would like to configure the page title at some point after the first streamlit call (i.e. not known up-front what it might be, depends on interactive or URL query params).

Solution

MVP: Smallest possible step has already been implemented, https://github.com/streamlit/streamlit/pull/1794.

Possible additions:

Preferred solution: Additional methods that enable re-configuration of the page title and favicon from anywhere in a streamlit app. e.g. something like:

def main():
    st.beta_set_page_config(
        page_title="Nightly Statistics",  # default page title
        layout="wide",
        initial_sidebar_state="auto"  # "expanded", "collapsed"
    )
    # some other streamlit code
    selected_view = st.sidebar.selectbox(
        label="Choose View",
        index=0,
        options=["Nightly Trends", "Nightly Failures", "Quarantine"],
    )
    st.beta_set_page_title(page_title=selected_view)

Community voting on feature requests enables the Streamlit team to understand which features are most important to our users.

If you'd like the Streamlit team to prioritize this feature request, please use the 👍 (thumbs up emoji) reaction in response to the initial post.

akrolsmir commented 4 years ago

Hi! Just wanted to say that as the one who implemented set_page_config for title and favicon, I'm also in favor of being able to mutate the page title & favicon later. To help motivate this, use cases (like the one you've already added) are super helpful in convincing the Product team that this is a good idea, so thank you!

MathCatsAnd commented 1 year ago

This works for me:

import streamlit as st

if 'bam!' not in st.session_state:
    st.set_page_config('A boring Title')
else:
    st.set_page_config(st.session_state.title, st.session_state.icon)

def bam():
    st.session_state['bam!'] = True
    st.session_state.title = st.session_state.title_input
    st.session_state.icon = st.session_state.icon_input

st.text_input('Page Title', key='title_input')
st.selectbox('Page Icon',[':cake:',':bird:',':cat:',':dog:'], key='icon_input')

st.button('Bam!', on_click=bam)

4F2F7E5E-8891-430D-8832-4652A6A71062

adumont commented 1 year ago

That's an elegant way, works for me! Thanks.