Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,168 @@
|
|
1 |
import streamlit as st
|
2 |
|
|
|
|
|
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
# --- SHARED ON ALL PAGES ---
|
6 |
st.logo(image="images/menu_book_60dp_75FBFD.png")
|
|
|
1 |
import streamlit as st
|
2 |
|
3 |
+
import time
|
4 |
+
from datetime import datetime
|
5 |
|
6 |
+
# Set page config
|
7 |
+
st.set_page_config(page_title="Sidebar Status Indicator", layout="wide")
|
8 |
+
|
9 |
+
# Initialize session state
|
10 |
+
if 'process_running' not in st.session_state:
|
11 |
+
st.session_state.process_running = False
|
12 |
+
if 'last_update' not in st.session_state:
|
13 |
+
st.session_state.last_update = datetime.now().strftime("%H:%M:%S")
|
14 |
+
if 'process_name' not in st.session_state:
|
15 |
+
st.session_state.process_name = ""
|
16 |
+
|
17 |
+
# Functions to handle process state
|
18 |
+
def start_process(name):
|
19 |
+
st.session_state.process_running = True
|
20 |
+
st.session_state.process_name = name
|
21 |
+
st.session_state.last_update = datetime.now().strftime("%H:%M:%S")
|
22 |
+
|
23 |
+
def stop_process():
|
24 |
+
st.session_state.process_running = False
|
25 |
+
st.session_state.last_update = datetime.now().strftime("%H:%M:%S")
|
26 |
+
|
27 |
+
# Function to run a simulated process
|
28 |
+
def run_process(name, duration=3):
|
29 |
+
start_process(name)
|
30 |
+
|
31 |
+
# Create a progress bar in the main area
|
32 |
+
progress_text = f"Running {name}..."
|
33 |
+
progress_bar = st.progress(0)
|
34 |
+
|
35 |
+
# Simulate work
|
36 |
+
for percent_complete in range(100):
|
37 |
+
time.sleep(duration/100)
|
38 |
+
progress_bar.progress(percent_complete + 1, text=progress_text)
|
39 |
+
|
40 |
+
# Mark process as complete
|
41 |
+
stop_process()
|
42 |
+
st.success(f"{name} completed!")
|
43 |
+
|
44 |
+
# This will trigger a rerun to update the sidebar
|
45 |
+
st.experimental_rerun()
|
46 |
+
|
47 |
+
# Configure the sidebar with our status widget
|
48 |
+
with st.sidebar:
|
49 |
+
st.title("App Status")
|
50 |
+
|
51 |
+
# Status indicator
|
52 |
+
status_container = st.container()
|
53 |
+
with status_container:
|
54 |
+
# Style based on current status
|
55 |
+
if st.session_state.process_running:
|
56 |
+
st.warning(f"⚙️ RUNNING: {st.session_state.process_name}")
|
57 |
+
else:
|
58 |
+
st.success("✅ IDLE")
|
59 |
+
|
60 |
+
# Last update time
|
61 |
+
st.caption(f"Last update: {st.session_state.last_update}")
|
62 |
+
|
63 |
+
# Stop button (only show when process is running)
|
64 |
+
if st.session_state.process_running:
|
65 |
+
if st.button("⏹️ Stop Process"):
|
66 |
+
stop_process()
|
67 |
+
st.experimental_rerun()
|
68 |
+
|
69 |
+
# Add a separator
|
70 |
+
st.markdown("---")
|
71 |
+
|
72 |
+
# Navigation options
|
73 |
+
st.subheader("Navigation")
|
74 |
+
nav_selection = st.radio("Go to:", ["Home", "Section 1", "Section 2", "Section 3"])
|
75 |
+
|
76 |
+
# Additional sidebar content
|
77 |
+
st.markdown("---")
|
78 |
+
st.markdown("### App Info")
|
79 |
+
st.info("This app demonstrates using the sidebar for a persistent status indicator.")
|
80 |
+
|
81 |
+
# Main content area based on navigation
|
82 |
+
st.title("App with Sidebar Status")
|
83 |
+
|
84 |
+
# Display content based on navigation selection
|
85 |
+
if nav_selection == "Home":
|
86 |
+
st.header("Home")
|
87 |
+
st.write("Welcome to the application. Use the sidebar to navigate and view the current status.")
|
88 |
+
|
89 |
+
# Add a simple process trigger
|
90 |
+
if st.button("Run Quick Process"):
|
91 |
+
run_process("Quick Process", 2)
|
92 |
+
|
93 |
+
# Add sample content
|
94 |
+
st.markdown("### Sample Content")
|
95 |
+
st.write("Scroll down to see more content while the sidebar remains fixed.")
|
96 |
+
|
97 |
+
for i in range(15):
|
98 |
+
st.write(f"Content line {i}")
|
99 |
+
|
100 |
+
elif nav_selection == "Section 1":
|
101 |
+
st.header("Section 1")
|
102 |
+
st.write("This is Section 1 of the application.")
|
103 |
+
|
104 |
+
col1, col2 = st.columns(2)
|
105 |
+
with col1:
|
106 |
+
if st.button("Run Process A"):
|
107 |
+
run_process("Process A", 3)
|
108 |
+
|
109 |
+
with col2:
|
110 |
+
if st.button("Run Process B"):
|
111 |
+
run_process("Process B", 4)
|
112 |
+
|
113 |
+
# Add sample content
|
114 |
+
for i in range(15):
|
115 |
+
st.write(f"Section 1 content line {i}")
|
116 |
+
|
117 |
+
elif nav_selection == "Section 2":
|
118 |
+
st.header("Section 2")
|
119 |
+
st.write("This is Section 2 of the application.")
|
120 |
+
|
121 |
+
# Add a more complex process trigger
|
122 |
+
process_type = st.selectbox("Select Process Type", ["Data Analysis", "Model Training", "Report Generation"])
|
123 |
+
|
124 |
+
if st.button("Start Selected Process"):
|
125 |
+
run_process(process_type, 5)
|
126 |
+
|
127 |
+
# Add sample content
|
128 |
+
for i in range(15):
|
129 |
+
st.write(f"Section 2 content line {i}")
|
130 |
+
|
131 |
+
elif nav_selection == "Section 3":
|
132 |
+
st.header("Section 3")
|
133 |
+
st.write("This is Section 3 of the application.")
|
134 |
+
|
135 |
+
# Add tabs within the section
|
136 |
+
tab1, tab2 = st.tabs(["Tab A", "Tab B"])
|
137 |
+
|
138 |
+
with tab1:
|
139 |
+
st.subheader("Tab A Content")
|
140 |
+
if st.button("Run Tab A Process"):
|
141 |
+
run_process("Tab A Process", 3)
|
142 |
+
|
143 |
+
for i in range(10):
|
144 |
+
st.write(f"Tab A content line {i}")
|
145 |
+
|
146 |
+
with tab2:
|
147 |
+
st.subheader("Tab B Content")
|
148 |
+
if st.button("Run Tab B Process"):
|
149 |
+
run_process("Tab B Process", 4)
|
150 |
+
|
151 |
+
for i in range(10):
|
152 |
+
st.write(f"Tab B content line {i}")
|
153 |
+
|
154 |
+
# Add additional content to ensure scrollability
|
155 |
+
st.markdown("---")
|
156 |
+
st.subheader("Additional Information")
|
157 |
+
st.write("This section demonstrates that the sidebar status indicator remains visible while scrolling.")
|
158 |
+
|
159 |
+
for i in range(10):
|
160 |
+
st.write(f"Additional information line {i}")
|
161 |
+
|
162 |
+
# Add a back-to-top button at the bottom
|
163 |
+
if st.button("Back to Top"):
|
164 |
+
# This doesn't actually scroll to top, but it does refresh the page
|
165 |
+
pass
|
166 |
|
167 |
# --- SHARED ON ALL PAGES ---
|
168 |
st.logo(image="images/menu_book_60dp_75FBFD.png")
|