-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
230 lines (210 loc) · 5.9 KB
/
app.py
File metadata and controls
230 lines (210 loc) · 5.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
import streamlit as st
from modules.report import build_deck
from modules.storage import load_log, DATA_DIR
from modules.metrics import compute
from modules.units import UNIT_DEFS
from modules.ui import sidebar, kpi, charts, heatmap
st.set_page_config(page_title="Demby Analytics™", layout="wide")
# ---------- responsive CSS ----------
st.markdown("""
<style>
/* Base font scaling and mobile optimizations */
html {
font-size: 14px;
-webkit-text-size-adjust: 100%; /* Prevent font scaling in landscape */
}
@media (max-width: 480px) {
html { font-size: 16px }
/* Improve touch targets */
button, [role="button"] { min-height: 44px; }
/* Better mobile spacing */
.stMarkdown { padding: 0.5rem 0; }
.stButton button { width: 100%; }
}
/* Hide sidebar on narrow screens with backdrop */
@media (max-width: 600px) {
section[data-testid="stSidebar"] {
transform: translateX(-330px);
transition: transform .3s ease;
z-index: 999;
}
body.show-sidebar section[data-testid="stSidebar"] {
transform: translateX(0);
}
/* Add backdrop when sidebar is open */
body.show-sidebar::after {
content: '';
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0,0,0,0.5);
z-index: 998;
}
/* Hide Streamlit's default menu */
#MainMenu { display: none }
/* Improve mobile header */
header[data-testid="stHeader"] {
padding: 0.5rem 1rem;
background: rgba(255,255,255,0.9);
backdrop-filter: blur(10px);
}
}
/* KPI row responsive with better spacing */
.kpi-row {
display: flex;
gap: 1rem;
margin: 1rem 0;
}
@media (max-width: 600px) {
.kpi-row {
flex-direction: column;
gap: 0.5rem;
}
/* Improve metric cards on mobile */
.kpi-row .stMetric {
padding: 0.5rem;
border-radius: 8px;
background: #f8f9fa;
}
}
/* Chart improvements */
.vega-embed {
min-height: 240px !important;
}
/* Better touch interactions */
.vega-embed .marks text {
font-size: 14px !important;
}
@media (max-width: 600px) {
.vega-embed .marks text {
font-size: 16px !important;
}
/* Improve tooltip visibility on mobile */
.vega-tooltip {
font-size: 14px !important;
padding: 8px !important;
max-width: 200px !important;
}
}
/* Mobile-optimized title */
@media (max-width: 600px) {
h1 {
font-size: 1.5rem !important;
margin: 0.5rem 0 !important;
padding: 0 1rem !important;
}
}
/* Improve table responsiveness */
.stDataFrame {
width: 100% !important;
overflow-x: auto !important;
}
.stDataFrame table {
min-width: 100% !important;
}
/* Better mobile download button */
@media (max-width: 600px) {
.stDownloadButton {
position: sticky;
bottom: 1rem;
z-index: 100;
padding: 0 1rem;
}
.stDownloadButton button {
width: 100%;
margin: 0;
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
}
</style>
""", unsafe_allow_html=True)
# Add hamburger menu button with improved mobile styling
st.components.v1.html("""
<script>
const btn = document.createElement('button');
btn.innerText = '☰';
btn.style.cssText = `
position: fixed;
top: 1rem;
left: 1rem;
z-index: 1000;
background: #fff;
border: 1px solid #ddd;
border-radius: 8px;
padding: 0.75rem;
cursor: pointer;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
font-size: 1.2rem;
line-height: 1;
transition: all 0.2s ease;
`;
btn.onclick = () => {
document.body.classList.toggle('show-sidebar');
// Close sidebar when clicking backdrop
document.body.addEventListener('click', function closeSidebar(e) {
if (e.target === document.body) {
document.body.classList.remove('show-sidebar');
document.body.removeEventListener('click', closeSidebar);
}
});
};
if (document.body) {
document.body.appendChild(btn);
}
// Close sidebar on window resize if open
window.addEventListener('resize', () => {
if (window.innerWidth > 600) {
document.body.classList.remove('show-sidebar');
}
});
</script>
""", height=0)
# ---------- title ----------
st.markdown(
"<h1 style='text-align:center; margin:0; padding:1rem;'>"
"Demby Analytics™<br>"
"<span style='font-size:0.8em; font-weight:normal;'>"
"Psychic Physics Dashboard"
"</span></h1>",
unsafe_allow_html=True,
)
# --------------------------------
if "nickname" not in st.session_state:
st.info("Viewing demo data. Choose a nickname in the sidebar to start your own log!")
else:
st.caption(f"Your data file: {DATA_DIR / (st.session_state.nickname + '.csv')}")
df_raw = load_log()
sidebar.draw(df_raw) # sidebar first (may rerun)
df = compute(df_raw)
if df.empty:
st.warning("No data yet. Use the sidebar to log your first entry.")
st.stop()
# Add date selector for KPIs
st.markdown("### 📊 Key Performance Indicators")
col1, col2 = st.columns([1, 3])
with col1:
available_dates = df['date'].dt.date.tolist()
available_dates.reverse() # Most recent first
selected_date = st.selectbox(
"View KPIs for date:",
options=available_dates,
index=0, # Default to most recent (now first in list)
format_func=lambda x: x.strftime("%Y-%m-%d")
)
# Get data for selected date
selected_row = df[df['date'].dt.date == selected_date].iloc[0]
kpi.draw(df, selected_row)
st.caption(UNIT_DEFS)
chart_path = charts.draw(df) # main charts
heatmap.draw(df) # calendar view
# after all charts rendered
pptx_file = build_deck(df, {"juice_anx": chart_path})
with open(pptx_file, "rb") as f:
st.download_button(
"Download Board Deck",
data=f,
file_name=pptx_file.name,
mime="application/vnd.openxmlformats-officedocument.presentationml.presentation"
)