generated from gabrieltempass/streamlit-component-vue-vite-template
-
Notifications
You must be signed in to change notification settings - Fork 14
Examples
Gabriel Tem Pass edited this page May 5, 2024
·
3 revisions
A basic example:
import streamlit as st
from streamlit_navigation_bar import st_navbar
page = st_navbar(["Home", "Documentation", "Examples", "Community", "About"])
st.write(page)
An example with a sidebar and applying a custom style:
import streamlit as st
from streamlit_navigation_bar import st_navbar
st.set_page_config(initial_sidebar_state="collapsed")
pages = ["Home", "Library", "Tutorials", "Development", "Download"]
styles = {
"nav": {
"background-color": "rgb(123, 209, 146)",
},
"div": {
"max-width": "32rem",
},
"span": {
"border-radius": "0.5rem",
"color": "rgb(49, 51, 63)",
"margin": "0 0.125rem",
"padding": "0.4375rem 0.625rem",
},
"active": {
"background-color": "rgba(255, 255, 255, 0.25)",
},
"hover": {
"background-color": "rgba(255, 255, 255, 0.35)",
},
}
page = st_navbar(pages, styles=styles)
st.write(page)
with st.sidebar:
st.write("Sidebar")
An example using a logo, an external URL, multiple pages with content, among other things:
import os
import streamlit as st
from streamlit_navigation_bar import st_navbar
import pages as pg
st.set_page_config(initial_sidebar_state="collapsed")
pages = ["Install", "User Guide", "API", "Examples", "Community", "GitHub"]
parent_dir = os.path.dirname(os.path.abspath(__file__))
logo_path = os.path.join(parent_dir, "cubes.svg")
urls = {"GitHub": "https://github.com/gabrieltempass/streamlit-navigation-bar"}
styles = {
"nav": {
"background-color": "royalblue",
"justify-content": "left",
},
"img": {
"padding-right": "14px",
},
"span": {
"color": "white",
"padding": "14px",
},
"active": {
"background-color": "white",
"color": "var(--text-color)",
"font-weight": "normal",
"padding": "14px",
}
}
options = {
"show_menu": False,
"show_sidebar": False,
}
page = st_navbar(
pages,
logo_path=logo_path,
urls=urls,
styles=styles,
options=options,
)
functions = {
"Home": pg.show_home,
"Install": pg.show_install,
"User Guide": pg.show_user_guide,
"API": pg.show_api,
"Examples": pg.show_examples,
"Community": pg.show_community,
}
go_to = functions.get(page)
if go_to:
go_to()