Fix Streamlit server deployment: headless mode, default 7-day range, error handling

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Jose Manuel 2026-06-22 10:57:06 +02:00
parent 9d007563ca
commit 35d5bec8cc
2 changed files with 10 additions and 2 deletions

View File

@ -1,2 +1,5 @@
[server] [server]
port = 15001 port = 15001
headless = true
enableCORS = false
enableXsrfProtection = false

View File

@ -87,10 +87,11 @@ def _load_detail(campaign_id: str, date_from: str, date_to: str):
st.sidebar.title("Filtros") st.sidebar.title("Filtros")
today = date.today() today = date.today()
yesterday = today - timedelta(days=1) yesterday = today - timedelta(days=1)
default_from = yesterday - timedelta(days=6) # últimos 7 días por defecto
first_of_month = today.replace(day=1) first_of_month = today.replace(day=1)
c1, c2 = st.sidebar.columns(2) c1, c2 = st.sidebar.columns(2)
date_from = c1.date_input("Desde", value=first_of_month, max_value=yesterday) date_from = c1.date_input("Desde", value=default_from, max_value=yesterday)
date_to = c2.date_input("Hasta", value=yesterday, min_value=date_from, max_value=yesterday) date_to = c2.date_input("Hasta", value=yesterday, min_value=date_from, max_value=yesterday)
if st.sidebar.button("🔄 Actualizar", use_container_width=True): if st.sidebar.button("🔄 Actualizar", use_container_width=True):
@ -105,7 +106,11 @@ if date_from > date_to:
# ── Data ────────────────────────────────────────────────────────────────────── # ── Data ──────────────────────────────────────────────────────────────────────
try:
daily_rows, campaign_metrics, vertical_cpls = _load_data(date_from_str, date_to_str) daily_rows, campaign_metrics, vertical_cpls = _load_data(date_from_str, date_to_str)
except Exception as _e:
st.error(f"Error cargando datos de Meta API: {_e}")
st.stop()
# Aggregate daily totals with per-vertical margins # Aggregate daily totals with per-vertical margins
_daily: dict = {} _daily: dict = {}