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

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. 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
- 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}")
 
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}")