sbsmapper / app.py
georad's picture
Update app.py
869929b verified
raw
history blame
5.73 kB
import streamlit as st
import time
from datetime import datetime
# Set page config
st.set_page_config(page_title="Sidebar Status Indicator", layout="wide")
# Initialize session state
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 = ""
# Functions to handle process state
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")
# Function to run a simulated process
def run_process(name, duration=3):
start_process(name)
# Create a progress bar in the main area
progress_text = f"Running {name}..."
progress_bar = st.progress(0)
# Simulate work
for percent_complete in range(100):
time.sleep(duration/100)
progress_bar.progress(percent_complete + 1, text=progress_text)
# Mark process as complete
stop_process()
st.success(f"{name} completed!")
# This will trigger a rerun to update the sidebar
st.experimental_rerun()
# Configure the sidebar with our status widget
with st.sidebar:
st.title("App Status")
# Status indicator
status_container = st.container()
with status_container:
# Style based on current status
if st.session_state.process_running:
st.warning(f"⚙️ RUNNING: {st.session_state.process_name}")
else:
st.success("✅ IDLE")
# Last update time
st.caption(f"Last update: {st.session_state.last_update}")
# Stop button (only show when process is running)
if st.session_state.process_running:
if st.button("⏹️ Stop Process"):
stop_process()
st.experimental_rerun()
# Add a separator
st.markdown("---")
# Navigation options
st.subheader("Navigation")
nav_selection = st.radio("Go to:", ["Home", "Section 1", "Section 2", "Section 3"])
# Additional sidebar content
st.markdown("---")
st.markdown("### App Info")
st.info("This app demonstrates using the sidebar for a persistent status indicator.")
# Main content area based on navigation
st.title("App with Sidebar Status")
# Display content based on navigation selection
if nav_selection == "Home":
st.header("Home")
st.write("Welcome to the application. Use the sidebar to navigate and view the current status.")
# Add a simple process trigger
if st.button("Run Quick Process"):
run_process("Quick Process", 2)
# Add sample content
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)
# Add sample content
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.")
# Add a more complex process trigger
process_type = st.selectbox("Select Process Type", ["Data Analysis", "Model Training", "Report Generation"])
if st.button("Start Selected Process"):
run_process(process_type, 5)
# Add sample content
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.")
# Add tabs within the section
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}")
# Add additional content to ensure scrollability
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}")
# Add a back-to-top button at the bottom
if st.button("Back to Top"):
# This doesn't actually scroll to top, but it does refresh the page
pass
# --- SHARED ON ALL PAGES ---
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")
# --- PAGE SETUP ---
type_text_page = st.Page(
page="pages/type_text.py",
title="DEMO (work in progress)",
icon=":material/keyboard:",
default=True,)
# --- NAVIGATION SETUP ---
pg = st.navigation(pages=[type_text_page]) # WITHOUT SECTIONS
#pg = st.navigation({"Chapter_Index": [start_page], "Demo": [type_text_page, upload_file_page], "About": [about_page]}) # WITH SECTIONS
pg.run()