WaysAhead Global commited on
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +39 -20
src/streamlit_app.py
CHANGED
|
@@ -1,36 +1,55 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
from keplergl import KeplerGl
|
| 4 |
-
|
| 5 |
-
import os
|
| 6 |
|
| 7 |
st.set_page_config(layout="wide")
|
| 8 |
-
st.title("π Dubai Footfall β Kepler.gl Map
|
| 9 |
|
| 10 |
-
# --- Load
|
| 11 |
-
st.info("
|
| 12 |
try:
|
| 13 |
-
df = pd.read_excel("
|
| 14 |
df = df.dropna(subset=["latitude", "longitude"])
|
| 15 |
-
|
| 16 |
-
st.success(f"β
Loaded {len(df)} footfall records.")
|
| 17 |
except Exception as e:
|
| 18 |
-
st.error(f"β Failed to load
|
| 19 |
st.stop()
|
| 20 |
|
| 21 |
-
# ---
|
| 22 |
-
st.info("πΊοΈ Rendering Kepler.gl map...")
|
| 23 |
try:
|
| 24 |
-
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
-
# Save
|
| 28 |
-
|
| 29 |
-
|
|
|
|
| 30 |
|
| 31 |
-
#
|
| 32 |
-
with open(
|
| 33 |
-
|
| 34 |
-
st.success("β
Map rendered successfully.")
|
| 35 |
except Exception as e:
|
| 36 |
st.error(f"β Failed to render Kepler map: {e}")
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
from keplergl import KeplerGl
|
| 4 |
+
from streamlit.components.v1 import html
|
|
|
|
| 5 |
|
| 6 |
st.set_page_config(layout="wide")
|
| 7 |
+
st.title("π Dubai Footfall Visualization β Kepler.gl Map")
|
| 8 |
|
| 9 |
+
# --- Load Excel File ---
|
| 10 |
+
st.info("π€ Loading footfall data...")
|
| 11 |
try:
|
| 12 |
+
df = pd.read_excel("jj_with_footfall.xlsx")
|
| 13 |
df = df.dropna(subset=["latitude", "longitude"])
|
| 14 |
+
st.success(f"β
Loaded {len(df)} footfall points.")
|
|
|
|
| 15 |
except Exception as e:
|
| 16 |
+
st.error(f"β Failed to load data: {e}")
|
| 17 |
st.stop()
|
| 18 |
|
| 19 |
+
# --- Convert to Kepler data format ---
|
|
|
|
| 20 |
try:
|
| 21 |
+
config = {
|
| 22 |
+
"version": "v1",
|
| 23 |
+
"config": {
|
| 24 |
+
"visState": {
|
| 25 |
+
"layers": [{
|
| 26 |
+
"type": "point",
|
| 27 |
+
"config": {
|
| 28 |
+
"dataId": "Footfall",
|
| 29 |
+
"label": "Footfall Points",
|
| 30 |
+
"color": [255, 0, 0],
|
| 31 |
+
"columns": {"lat": "latitude", "lng": "longitude", "altitude": None},
|
| 32 |
+
"isVisible": True,
|
| 33 |
+
"visConfig": {
|
| 34 |
+
"radius": 10,
|
| 35 |
+
"opacity": 0.8,
|
| 36 |
+
"colorRange": {
|
| 37 |
+
"colors": ["#FF5733", "#FFBD33", "#75FF33"]
|
| 38 |
+
}
|
| 39 |
+
}
|
| 40 |
+
}
|
| 41 |
+
}]
|
| 42 |
+
}
|
| 43 |
+
}
|
| 44 |
+
}
|
| 45 |
|
| 46 |
+
# Save config and data
|
| 47 |
+
map_ = KeplerGl(data={"Footfall": df}, config=config)
|
| 48 |
+
map_.save_to_html(file_name="kepler_map.html", read_only=False)
|
| 49 |
+
st.success("β
Kepler map ready. Rendering...")
|
| 50 |
|
| 51 |
+
# Render inside Streamlit
|
| 52 |
+
with open("kepler_map.html", "r", encoding="utf-8") as f:
|
| 53 |
+
html(f.read(), height=700, width=1200)
|
|
|
|
| 54 |
except Exception as e:
|
| 55 |
st.error(f"β Failed to render Kepler map: {e}")
|