WaysAhead Global commited on
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +13 -11
src/streamlit_app.py
CHANGED
|
@@ -2,33 +2,35 @@ import streamlit as st
|
|
| 2 |
import pandas as pd
|
| 3 |
from keplergl import KeplerGl
|
| 4 |
import streamlit.components.v1 as components
|
|
|
|
| 5 |
|
| 6 |
st.set_page_config(layout="wide")
|
| 7 |
-
st.title("π Dubai Footfall β Kepler.gl
|
| 8 |
|
| 9 |
-
# --- Load Data ---
|
| 10 |
st.info("π¦ Loading footfall data...")
|
| 11 |
try:
|
| 12 |
df = pd.read_excel("data/jj_with_footfall.xlsx")
|
| 13 |
df = df.dropna(subset=["latitude", "longitude"])
|
| 14 |
df = df.astype({"latitude": float, "longitude": float})
|
| 15 |
-
df = df[["latitude", "longitude"]]
|
| 16 |
st.success(f"β
Loaded {len(df)} footfall records.")
|
| 17 |
except Exception as e:
|
| 18 |
st.error(f"β Failed to load footfall data: {e}")
|
| 19 |
st.stop()
|
| 20 |
|
| 21 |
-
# --- Render Kepler Map ---
|
| 22 |
st.info("πΊοΈ Rendering Kepler.gl map...")
|
| 23 |
try:
|
| 24 |
-
#
|
| 25 |
-
|
| 26 |
-
map_.save_to_html("kepler_output.html")
|
| 27 |
|
| 28 |
-
#
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
| 32 |
st.success("β
Map rendered successfully.")
|
| 33 |
except Exception as e:
|
| 34 |
st.error(f"β Failed to render Kepler map: {e}")
|
|
|
|
| 2 |
import pandas as pd
|
| 3 |
from keplergl import KeplerGl
|
| 4 |
import streamlit.components.v1 as components
|
| 5 |
+
import os
|
| 6 |
|
| 7 |
st.set_page_config(layout="wide")
|
| 8 |
+
st.title("π Dubai Footfall β Kepler.gl Map Viewer")
|
| 9 |
|
| 10 |
+
# --- Load Footfall Data ---
|
| 11 |
st.info("π¦ Loading footfall data...")
|
| 12 |
try:
|
| 13 |
df = pd.read_excel("data/jj_with_footfall.xlsx")
|
| 14 |
df = df.dropna(subset=["latitude", "longitude"])
|
| 15 |
df = df.astype({"latitude": float, "longitude": float})
|
|
|
|
| 16 |
st.success(f"β
Loaded {len(df)} footfall records.")
|
| 17 |
except Exception as e:
|
| 18 |
st.error(f"β Failed to load footfall data: {e}")
|
| 19 |
st.stop()
|
| 20 |
|
| 21 |
+
# --- Save & Render Kepler Map ---
|
| 22 |
st.info("πΊοΈ Rendering Kepler.gl map...")
|
| 23 |
try:
|
| 24 |
+
# Kepler expects a dictionary {name: DataFrame}
|
| 25 |
+
kepler_map = KeplerGl(height=600, data={"Footfall": df})
|
|
|
|
| 26 |
|
| 27 |
+
# Save the map to HTML
|
| 28 |
+
html_path = "kepler_map.html"
|
| 29 |
+
kepler_map.save_to_html(html_path)
|
| 30 |
+
|
| 31 |
+
# Load and display the HTML in Streamlit
|
| 32 |
+
with open(html_path, "r", encoding="utf-8") as f:
|
| 33 |
+
components.html(f.read(), height=650)
|
| 34 |
st.success("β
Map rendered successfully.")
|
| 35 |
except Exception as e:
|
| 36 |
st.error(f"β Failed to render Kepler map: {e}")
|