Skip to content

🐱  App logo

Submitted by Zachary Blackwood

Summary

Add a logo on top of the navigation bar of a multipage app. Note: st.logo has been released in Streamlit 1.35.0!

Functions

Add a logo (from logo_url) on the top of the navigation page of a multipage app.

Taken from the Streamlit forum. The url can either be a url to the image, or a local path to the image.

Parameters:

Name Type Description Default
logo_url str

URL/local path of the logo

required

Deprecated

This function is deprecated. Use st.logo() instead.

Source code in src/streamlit_extras/app_logo/__init__.py
@extra
def add_logo(logo_url: str, height: int = 120) -> None:
    """Add a logo (from logo_url) on the top of the navigation page of a multipage app.

    Taken from the Streamlit forum. The url can either be a url to the image, or a local
    path to the image.

    Args:
        logo_url (str): URL/local path of the logo

    !!! warning "Deprecated"
        This function is deprecated. Use
        [`st.logo()`](https://docs.streamlit.io/develop/api-reference/media/st.logo)
        instead.
    """
    show_deprecation_warning(
        "add_logo is deprecated. Use `st.logo()` instead. "
        "See https://docs.streamlit.io/develop/api-reference/media/st.logo",
        show_once=True,
    )

    if is_url(logo_url):
        logo = f"url({logo_url})"
    else:
        logo = f"url(data:image/png;base64,{base64.b64encode(Path(logo_url).read_bytes()).decode()})"

    st.html(
        f"""
        <style>
            [data-testid="stSidebarNav"] {{
                background-image: {logo};
                background-repeat: no-repeat;
                padding-top: {height - 40}px;
                background-position: 20px 20px;
            }}
        </style>
        """
    )

Import:

from streamlit_extras.app_logo import add_logo # (1)!
  1. You should add this to the top of your .py file 🛠

Examples

example

def example() -> None:
    if st.checkbox("Use url", value=True):
        add_logo("http://placekitten.com/120/120")
    else:
        add_logo("gallery/kitty.jpeg", height=300)
    st.write("👈 Check out the cat in the nav-bar!")