|
import streamlit as st |
|
|
|
import time |
|
from datetime import datetime |
|
|
|
|
|
st.set_page_config(page_title="Sidebar Status Indicator", layout="wide") |
|
|
|
|
|
if 'process_running' not in st.session_state: |
|
st.session_state.process_running = False |
|
if 'last_update' not in st.session_state: |
|
st.session_state.last_update = datetime.now().strftime("%H:%M:%S") |
|
if 'process_name' not in st.session_state: |
|
st.session_state.process_name = "" |
|
|
|
|
|
def start_process(name): |
|
st.session_state.process_running = True |
|
st.session_state.process_name = name |
|
st.session_state.last_update = datetime.now().strftime("%H:%M:%S") |
|
|
|
def stop_process(): |
|
st.session_state.process_running = False |
|
st.session_state.last_update = datetime.now().strftime("%H:%M:%S") |
|
|
|
|
|
def run_process(name, duration=3): |
|
start_process(name) |
|
|
|
|
|
progress_text = f"Running {name}..." |
|
progress_bar = st.progress(0) |
|
|
|
|
|
for percent_complete in range(100): |
|
time.sleep(duration/100) |
|
progress_bar.progress(percent_complete + 1, text=progress_text) |
|
|
|
|
|
stop_process() |
|
st.success(f"{name} completed!") |
|
|
|
|
|
st.experimental_rerun() |
|
|
|
|
|
with st.sidebar: |
|
st.title("App Status") |
|
|
|
|
|
status_container = st.container() |
|
with status_container: |
|
|
|
if st.session_state.process_running: |
|
st.warning(f"⚙️ RUNNING: {st.session_state.process_name}") |
|
else: |
|
st.success("✅ IDLE") |
|
|
|
|
|
st.caption(f"Last update: {st.session_state.last_update}") |
|
|
|
|
|
if st.session_state.process_running: |
|
if st.button("⏹️ Stop Process"): |
|
stop_process() |
|
st.experimental_rerun() |
|
|
|
|
|
st.markdown("---") |
|
|
|
|
|
st.subheader("Navigation") |
|
nav_selection = st.radio("Go to:", ["Home", "Section 1", "Section 2", "Section 3"]) |
|
|
|
|
|
st.markdown("---") |
|
st.markdown("### App Info") |
|
st.info("This app demonstrates using the sidebar for a persistent status indicator.") |
|
|
|
|
|
st.title("App with Sidebar Status") |
|
|
|
|
|
if nav_selection == "Home": |
|
st.header("Home") |
|
st.write("Welcome to the application. Use the sidebar to navigate and view the current status.") |
|
|
|
|
|
if st.button("Run Quick Process"): |
|
run_process("Quick Process", 2) |
|
|
|
|
|
st.markdown("### Sample Content") |
|
st.write("Scroll down to see more content while the sidebar remains fixed.") |
|
|
|
for i in range(15): |
|
st.write(f"Content line {i}") |
|
|
|
elif nav_selection == "Section 1": |
|
st.header("Section 1") |
|
st.write("This is Section 1 of the application.") |
|
|
|
col1, col2 = st.columns(2) |
|
with col1: |
|
if st.button("Run Process A"): |
|
run_process("Process A", 3) |
|
|
|
with col2: |
|
if st.button("Run Process B"): |
|
run_process("Process B", 4) |
|
|
|
|
|
for i in range(15): |
|
st.write(f"Section 1 content line {i}") |
|
|
|
elif nav_selection == "Section 2": |
|
st.header("Section 2") |
|
st.write("This is Section 2 of the application.") |
|
|
|
|
|
process_type = st.selectbox("Select Process Type", ["Data Analysis", "Model Training", "Report Generation"]) |
|
|
|
if st.button("Start Selected Process"): |
|
run_process(process_type, 5) |
|
|
|
|
|
for i in range(15): |
|
st.write(f"Section 2 content line {i}") |
|
|
|
elif nav_selection == "Section 3": |
|
st.header("Section 3") |
|
st.write("This is Section 3 of the application.") |
|
|
|
|
|
tab1, tab2 = st.tabs(["Tab A", "Tab B"]) |
|
|
|
with tab1: |
|
st.subheader("Tab A Content") |
|
if st.button("Run Tab A Process"): |
|
run_process("Tab A Process", 3) |
|
|
|
for i in range(10): |
|
st.write(f"Tab A content line {i}") |
|
|
|
with tab2: |
|
st.subheader("Tab B Content") |
|
if st.button("Run Tab B Process"): |
|
run_process("Tab B Process", 4) |
|
|
|
for i in range(10): |
|
st.write(f"Tab B content line {i}") |
|
|
|
|
|
st.markdown("---") |
|
st.subheader("Additional Information") |
|
st.write("This section demonstrates that the sidebar status indicator remains visible while scrolling.") |
|
|
|
for i in range(10): |
|
st.write(f"Additional information line {i}") |
|
|
|
|
|
if st.button("Back to Top"): |
|
|
|
pass |
|
|
|
|
|
st.logo(image="images/menu_book_60dp_75FBFD.png") |
|
st.sidebar.title("SBS V2.0 mapper") |
|
st.sidebar.subheader("(work in progress)") |
|
st.sidebar.text("Demo by JA-RAD") |
|
|
|
|
|
type_text_page = st.Page( |
|
page="pages/type_text.py", |
|
title="DEMO (work in progress)", |
|
icon=":material/keyboard:", |
|
default=True,) |
|
|
|
|
|
pg = st.navigation(pages=[type_text_page]) |
|
|
|
pg.run() |