Skip to main content

Components and Frameworks to give new features to streamlit

Project description

streamlit-plugins

Components and Frameworks to give new features to streamlit

Demo Multipage with Navbar

Component

The Navbar and Loader component are inherited from Hydralit components, only to give support to the multilit framework. But this version has improve the interface and loaders to be more user-friendly.

Navbar (Inherit from Hydralit Components)

Component to use when you want to have a navbar in your streamlit app. It can be used with native multipage streamlit, or use the multilit framework.

If you want to use the native multipage streamlit, you can use the st_navbar function to create the navbar.

This component it returns the id of the defined menu that has to run the page.

This is an example of multipage with native streamlit

import streamlit as st

if "logged_in" not in st.session_state:
    st.session_state.logged_in = False

def login():
    if st.button("Log in"):
        st.session_state.logged_in = True
        st.rerun()

def logout():
    if st.button("Log out"):
        st.session_state.logged_in = False
        st.rerun()

login_page = st.Page(login, title="Log in", icon=":material/login:")
logout_page = st.Page(logout, title="Log out", icon=":material/logout:")

dashboard = st.Page(
    "reports/dashboard.py", title="Dashboard", icon=":material/dashboard:", default=True
)
bugs = st.Page("reports/bugs.py", title="Bug reports", icon=":material/bug_report:")
alerts = st.Page(
    "reports/alerts.py", title="System alerts", icon=":material/notification_important:"
)

search = st.Page("tools/search.py", title="Search", icon=":material/search:")
history = st.Page("tools/history.py", title="History", icon=":material/history:")

if st.session_state.logged_in:
    pg = st.navigation(
        {
            "Account": [logout_page],
            "Reports": [dashboard, bugs, alerts],
            "Tools": [search, history],
        }
    )
else:
    pg = st.navigation([login_page])

pg.run()

And if you want to use streamlit Navbar, it has to be addapted to this code:

import streamlit as st

st.set_page_config(layout="wide")

if "logged_in" not in st.session_state:
    st.session_state.logged_in = False

if "app_id" not in st.session_state:
    st.session_state.app_id = None

def login():
    if st.button("Log in"):
        st.session_state.logged_in = True
        st.session_state.app_id = "app_default"
        st.rerun()

def logout():
    if st.button("Log out"):
        st.session_state.logged_in = False
        st.session_state.app_id = None
        st.rerun()


login_page = st.Page(login, title="Log in", icon=":material/login:")
logout_page = st.Page(logout, title="Log out", icon=":material/logout:")

dashboard = st.Page(
    "reports/dashboard.py", title="Dashboard", icon=":material/dashboard:", default=True
)
bugs = st.Page("reports/bugs.py", title="Bug reports", icon=":material/bug_report:")
alerts = st.Page(
    "reports/alerts.py", title="System alerts", icon=":material/notification_important:"
)

search = st.Page("tools/search.py", title="Search", icon=":material/search:")
history = st.Page("tools/history.py", title="History", icon=":material/history:")

# HERE IS THE CHANGE
from streamlit_plugins.components.navbar import st_navbar, build_menu_from_st_pages

menu_data, app_map = build_menu_from_st_pages(
    {"Reports": [dashboard, bugs, alerts]}, {"Tools": [search, history]},
    login_app=login_page,
    logout_app=logout_page,
)

app_id = st_navbar(
    menu_definition=menu_data if st.session_state.logged_in else [],
    login_name=logout_page.title if st.session_state.logged_in else login_page.title,
    hide_streamlit_markers=False,
    override_app_selected_id=st.session_state.app_id,
    sticky_nav=True,  # at the top or not
    sticky_mode='pinned',  # sticky or pinned
)
if app_id == "app_login":
    if st.session_state.logged_in:
        app_id = "app_logout"

st.session_state.app_id = None  # Added to fix login/logout issue
app_map[app_id]._can_be_called = True
app_map[app_id].run()


# if st.session_state.logged_in:
#     pg = st.navigation(
#         {
#             "Account": [logout_page],
#             "Reports": [dashboard, bugs, alerts],
#             "Tools": [search, history],
#         },
#         position="hidden"
#     )
#
# else:
#     pg = st.navigation([login_page], position="hidden")
#
#
# pg.run()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

streamlit_component_navbar-0.3.0.tar.gz (5.1 MB view details)

Uploaded Source

Built Distribution

File details

Details for the file streamlit_component_navbar-0.3.0.tar.gz.

File metadata

File hashes

Hashes for streamlit_component_navbar-0.3.0.tar.gz
Algorithm Hash digest
SHA256 b589f3cf47d097ae44334427c3e098d1d56fff819c633fab4b8713197ce86c58
MD5 82a86d6c57ed72ca77884cacc36b9a03
BLAKE2b-256 4702b6646d0e24c963d60c02d3a666a72dc90e06261c87eb991f5d2d30b06c80

See more details on using hashes here.

File details

Details for the file streamlit_component_navbar-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for streamlit_component_navbar-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5e29cdb4267c96d5f445c9c48876a16a8c7a001a6f3ca8e9b26a5078b8c50f60
MD5 8fb4b992f9e3d57d6374de702f72af10
BLAKE2b-256 d80d4a7639adad3f46ad9f72f1dab3f8aea0e26b3ce2719bb8340e501e12d10d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page