×

Configuring Streamlit Page

Cofigure Streamlit Feature

When creating a streamlit app it is desirable to have the right title appear inside the tab name in your browser with a distinct icon. Moreover, there are styles and elements that you might want to define for the entire application.

There are 2 ways you can configure your page.

Method 1: Directly defining in set_page_config()

Streamlit allows you to configure your page accordingly using set_page_config().

To set the page title and the desired icon, use the properties page_title and page_icon respectively

import streamlit as st

st.set_page_config(page_title='My First App', page_icon=':smiley')

st.title("Page Configuration")
Page Config 1 Streamlit 1

You may also set the layout of the page using layout

st.set_page_config(page_title='My First App', page_icon=':smiley', layout="wide") 
Page Config Stramlit 2

You can also decide on the default state of the sidebar as either expanded or collapsed using initial_sidebar_state property

st.set_page_config(page_title='My First App', page_icon=':smiley', 
                  layout="wide", initial_sidebar_state='collapsed')

st.sidebar.success("Menu")
Collapsed Streamlit
st.set_page_config(page_title='My First App', page_icon=':smiley', 
                   layout="wide", initial_sidebar_state='expanded')
Sidebar Expanded Streamlit

Method 2: Defining properties in a dictionary

While defining the page configuration there might be many properties that are required to be changed from the default setting or there might be more than one set of page configurations.

In that case, it is desirable to define the properties in a dictionary as keywords.

stramlit.set_page_config(**<dictionary>) can be used to configure the page using properties defined in the dictionary.

  • Note: We use ( ** ) before dictionary because we are calling keyword arguments or kwargs
PAGE_CONFIG = {"page_title" : "My First App", "page_icon":":smiley", "layout": "centered"}

st.set_page_config(**PAGE_CONFIG)