Create an app showing an interactive NYC map visualization. Mock data: - Food truck locations (100 points) - Pedestrian activity heatmap Features: - Interactive map centered on NYC - Toggle layers: * Food trucks with popups * Pedestrian heatmap * Animated routes * Taxi clusters Controls: - Time slider - Borough filters - Color schemes - Map style (street/satellite) - Heatmap and cluster settings Include zoom/pan and stats panel showing data summaries.
Drop files here
or click to upload
import streamlit as st
import pandas as pd
import numpy as np
import pydeck as pdk
# Mock data
num_food_trucks = 100
np.random.seed(0)
food_truck_locations = pd.DataFrame({
'latitude': np.random.uniform(40.6, 40.9, num_food_trucks),
'longitude': np.random.uniform(-74.1, -73.9, num_food_trucks),
})
# Function to generate pedestrian activity heatmap data
def generate_heatmap_data():
heatmap_data = pd.DataFrame({
'latitude': np.random.uniform(40.6, 40.9, 500),
'longitude': np.random.uniform(-74.1, -73.9, 500),
'intensity': np.random.rand(500) * 100,
})
return heatmap_data
heatmap_data = generate_heatmap_data()
# App layout
st.title('Interactive NYC Map Visualization')
# Controls
st.sidebar.header('Controls')
map_style = st.sidebar.selectbox('Map Style', ['street', 'satellite'])
show_food_trucks = st.sidebar.checkbox('Show Food Trucks', value=True)
show_heatmap = st.sidebar.checkbox('Show Pedestrian Heatmap', value=True)
# Time slider
st.sidebar.subheader('Time Controls')
time_frame = st.sidebar.slider('Time frame', min_value=0, max_value=24, value=(0, 24))
# Filter boroughs
boroughs = st.sidebar.multiselect('Select Boroughs', ['Manhattan', 'Brooklyn', 'Queens', 'Bronx', 'Staten Island'], default=['Manhattan', 'Brooklyn'])
# Create deck map with layers
layers = []
if show_food_trucks:
layers.append(pdk.Layer(
'ScatterplotLayer',
data=food_truck_locations,
get_position='[longitude, latitude]',
get_fill_color='[255, 0, 0, 200]',
radius_pixels=100,
pickable=True,
line_color='white',
line_width=2,
# Popup information
get_line_color=[0, 0, 0],
pickable=True,
))
if show_heatmap:
layers.append(pdk.Layer(
'HeatmapLayer',
data=heatmap_data,
get_position='[longitude, latitude]',
radius_pixels=30,
threshold=0.1,
get_weight='intensity',
))
# Set view state
view_state = pdk.ViewState(
latitude=40.7128,
longitude=-74.0060,
zoom=12,
pitch=0,
bearing=0
)
# Create Map
map = pdk.Deck(
layers=layers,
initial_view_state=view_state,
map_style=map_style.lower(),
tooltip=True,
)
st.pydeck_chart(map)
# Stats panel
st.sidebar.subheader('Statistics')
if show_food_trucks:
st.sidebar.markdown(f'**Food Trucks:** {len(food_truck_locations)}')
if show_heatmap:
st.sidebar.markdown(f'**Pedestrian Heatmap Points:** {len(heatmap_data)}')
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?