WaysAhead Global commited on
Commit
7493fbc
Β·
verified Β·
1 Parent(s): 3eb2866

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. 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 Interactive Map")
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
- # Note: we provide data as a dict, not a single dataframe
25
- map_ = KeplerGl(height=600, data={"Footfall Points": df})
26
- map_.save_to_html("kepler_output.html")
27
 
28
- # Display the HTML inside Streamlit
29
- with open("kepler_output.html", "r", encoding="utf-8") as f:
30
- html = f.read()
31
- components.html(html, height=650)
 
 
 
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}")