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.
To upload files, please first save the app
import streamlit as st
import pandas as pd
import numpy as np
import pydeck as pdk
from folium import Map, LayerControl
from streamlit_folium import folium_static
import datetime
# Set page config
st.set_page_config(layout="wide", page_title="NYC Map Visualization")
# Generate mock data
@st.cache_data
def generate_mock_data():
# Food truck locations around NYC
n_trucks = 100
trucks_df = pd.DataFrame({
'name': [f'Food Truck #{i}' for i in range(n_trucks)],
'lat': np.random.normal(40.7128, 0.1, n_trucks),
'lon': np.random.normal(-74.0060, 0.1, n_trucks),
'cuisine': np.random.choice(['Hot Dogs', 'Tacos', 'Halal', 'Ice Cream', 'Pizza'], n_trucks),
'rating': np.random.uniform(3.0, 5.0, n_trucks),
'borough': np.random.choice(['Manhattan', 'Brooklyn', 'Queens', 'Bronx', 'Staten Island'], n_trucks)
})
# Pedestrian activity (heatmap)
n_points = 1000
heatmap_df = pd.DataFrame({
'lat': np.random.normal(40.7128, 0.1, n_points),
'lon': np.random.normal(-74.0060, 0.1, n_points),
'intensity': np.random.exponential(1, n_points)
})
return trucks_df, heatmap_df
# Initialize data
trucks_df, heatmap_df = generate_mock_data()
# Sidebar controls
st.sidebar.title("Map Controls")
# Time slider
time_range = st.sidebar.slider(
"Time Range",
min_value=datetime.time(0, 0),
max_value=datetime.time(23, 59),
value=(datetime.time(9, 0), datetime.time(17, 0))
)
# Borough filter
boroughs = st.sidebar.multiselect(
"Borough Filter",
['Manhattan', 'Brooklyn', 'Queens', 'Bronx', 'Staten Island'],
default=['Manhattan']
)
# Map style
map_style = st.sidebar.selectbox(
"Map Style",
['streets-v11', 'satellite-v9', 'light-v10', 'dark-v10']
)
# Layer toggles
st.sidebar.subheader("Layers")
show_trucks = st.sidebar.checkbox("Food Trucks", value=True)
show_heatmap = st.sidebar.checkbox("Pedestrian Heatmap", value=True)
show_clusters = st.sidebar.checkbox("Taxi Clusters", value=False)
# Heatmap settings
if show_heatmap:
st.sidebar.subheader("Heatmap Settings")
heatmap_radius = st.sidebar.slider("Radius", 10, 100, 50)
heatmap_intensity = st.sidebar.slider("Intensity", 0.1, 2.0, 1.0)
# Main content
st.title("NYC Interactive Map")
# Create columns for map and stats
col1, col2 = st.columns([7, 3])
with col1:
# Initial view state
initial_view_state = pdk.ViewState(
latitude=40.7128,
longitude=-74.0060,
zoom=11,
pitch=0
)
# Define layers
layers = []
if show_trucks:
trucks_layer = pdk.Layer(
'ScatterplotLayer',
data=trucks_df[trucks_df['borough'].isin(boroughs)],
get_position=['lon', 'lat'],
get_radius=100,
get_fill_color=[255, 0, 0, 140],
pickable=True
)
layers.append(trucks_layer)
if show_heatmap:
heatmap_layer = pdk.Layer(
'HeatmapLayer',
data=heatmap_df,
get_position=['lon', 'lat'],
get_weight='intensity',
radiusPixels=heatmap_radius,
intensity=heatmap_intensity
)
layers.append(heatmap_layer)
# Create deck
deck = pdk.Deck(
map_style=f'mapbox://{map_style}',
initial_view_state=initial_view_state,
layers=layers,
tooltip={
'html': '<b>Food Truck:</b> {name}<br/>'
'<b>Cuisine:</b> {cuisine}<br/>'
'<b>Rating:</b> {rating:.1f}⭐',
'style': {
'backgroundColor': 'steelblue',
'color': 'white'
}
}
)
st.pydeck_chart(deck)
with col2:
# Stats panel
st.subheader("Statistics")
# Food truck stats
st.write("Food Trucks")
filtered_trucks = trucks_df[trucks_df['borough'].isin(boroughs)]
st.metric("Total Trucks", len(filtered_trucks))
st.metric("Average Rating", f"{filtered_trucks['rating'].mean():.1f}⭐")
# Top cuisines
st.write("Top Cuisines")
cuisine_counts = filtered_trucks['cuisine'].value_counts()
st.bar_chart(cuisine_counts)
# Borough distribution
st.write("Borough Distribution")
borough_counts = filtered_trucks['borough'].value_counts()
st.bar_chart(borough_counts)
# Footer
st.markdown("---")
st.markdown("Data is simulated for demonstration purposes.")
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?