Create an app showing an interactive Yakima map visualization. Mock data: - Hop farm field blocks Features: - Interactive map centered on Yakima hop farms 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 pydeck as pdk
import numpy as np
st.set_page_config(layout="wide", page_title="Yakima Hop Farms Visualization")
# Generate mock data for hop farms
np.random.seed(42)
N_FARMS = 100
# Center coordinates for Yakima Valley hop growing region
YAKIMA_LAT = 46.6021
YAKIMA_LON = -120.5059
# Generate random farm locations in Yakima Valley area
lat_spread = 0.2
lon_spread = 0.3
data = pd.DataFrame({
'farm_id': range(N_FARMS),
'lat': YAKIMA_LAT + np.random.uniform(-lat_spread, lat_spread, N_FARMS),
'lon': YAKIMA_LON + np.random.uniform(-lon_spread, lon_spread, N_FARMS),
'acres': np.random.uniform(10, 100, N_FARMS),
'borough': np.random.choice(['Moxee', 'Toppenish', 'Granger', 'Zillah'], N_FARMS),
'hop_variety': np.random.choice(['Cascade', 'Centennial', 'Citra', 'Mosaic'], N_FARMS),
'year_established': np.random.randint(1950, 2023, N_FARMS)
})
# Sidebar controls
st.sidebar.title('Map Controls')
# Time filter
year_range = st.sidebar.slider(
'Year Established',
min_value=int(data['year_established'].min()),
max_value=int(data['year_established'].max()),
value=(1950, 2023)
)
# Borough filter
boroughs = st.sidebar.multiselect(
'Boroughs',
options=sorted(data['borough'].unique()),
default=sorted(data['borough'].unique())
)
# Map style
map_style = st.sidebar.selectbox(
'Map Style',
options=['mapbox://styles/mapbox/light-v9',
'mapbox://styles/mapbox/dark-v9',
'mapbox://styles/mapbox/satellite-v9']
)
# Visualization type
viz_type = st.sidebar.selectbox(
'Visualization Type',
options=['Scatter', 'Heatmap', 'Cluster']
)
# Filter data based on selections
filtered_data = data[
(data['year_established'].between(year_range[0], year_range[1])) &
(data['borough'].isin(boroughs))
]
# Main content
st.title('Yakima Valley Hop Farms')
col1, col2 = st.columns([3, 1])
with col1:
# Create the map layer based on visualization type
if viz_type == 'Scatter':
layer = pdk.Layer(
'ScatterplotLayer',
filtered_data,
get_position=['lon', 'lat'],
get_radius='acres',
radius_scale=20,
radius_min_pixels=5,
radius_max_pixels=30,
get_fill_color=[255, 140, 0, 140],
pickable=True
)
elif viz_type == 'Heatmap':
layer = pdk.Layer(
'HeatmapLayer',
filtered_data,
get_position=['lon', 'lat'],
get_weight='acres',
pickable=True
)
else: # Cluster
layer = pdk.Layer(
'ColumnLayer',
filtered_data,
get_position=['lon', 'lat'],
get_elevation='acres',
elevation_scale=10,
radius=50,
pickable=True
)
# Create the map view
view_state = pdk.ViewState(
latitude=YAKIMA_LAT,
longitude=YAKIMA_LON,
zoom=10,
pitch=45
)
# Render the map
r = pdk.Deck(
layers=[layer],
initial_view_state=view_state,
map_style=map_style,
tooltip={
'html': '<b>Farm ID:</b> {farm_id}<br/>'
'<b>Borough:</b> {borough}<br/>'
'<b>Acres:</b> {acres:.1f}<br/>'
'<b>Hop Variety:</b> {hop_variety}<br/>'
'<b>Established:</b> {year_established}',
'style': {
'backgroundColor': 'steelblue',
'color': 'white'
}
}
)
st.pydeck_chart(r)
with col2:
st.subheader('Summary Statistics')
# Display summary stats
st.write('**Total Farms:**', len(filtered_data))
st.write('**Total Acreage:**', f"{filtered_data['acres'].sum():.1f}")
st.subheader('Borough Distribution')
borough_counts = filtered_data['borough'].value_counts()
st.bar_chart(borough_counts)
st.subheader('Hop Variety Distribution')
variety_counts = filtered_data['hop_variety'].value_counts()
st.bar_chart(variety_counts)
st.subheader('Average Farm Size by Borough')
avg_size = filtered_data.groupby('borough')['acres'].mean().round(1)
st.bar_chart(avg_size)
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?