Spaces:
Build error
Build error
Upload app.py
Browse files123456730 unmodified lines383940404141424344454647484943444546474849505150515253545556575859606162636465665667686970import streamlit as st
import pandas as pd
import altair as alt
import plotly.express as px
st.set_page_config(page_title="IL Crop Rotation Explorer", layout="wide")
30 unmodified lines title='Crop Coverage Over Time (Filtered)'
)
# ---- Heatmap: Crops by Land Use ----
heatmap_data = filtered.groupby(['GenLU', 'crop_name']).size().reset_index(name='count')
# ---- Treemap: Crops by Land Use ----
# Prepare the data (grouped field count)
treemap_data = (
filtered
.groupby(['GenLU', 'crop_name'])
.size()
.reset_index(name='field_count')
)
heatmap = alt.Chart(heatmap_data).mark_rect().encode(
x=alt.X('GenLU:N', title='General Land Use', sort=genlu_options),
y=alt.Y('crop_name:N', title='Dominant Crop', sort=crop_options),
color=alt.Color('count:Q', scale=alt.Scale(scheme='greens'), title='Field Count'),
tooltip=['GenLU', 'crop_name', 'count']
).properties(
width=800,
height=500,
title='Heatmap: Dominant Crops by General Land Use'
# Drop rows with missing GenLU or crop_name just in case
treemap_data = treemap_data.dropna(subset=['GenLU', 'crop_name'])
# Create treemap
treemap = px.treemap(
treemap_data,
path=['GenLU', 'crop_name'], # Hierarchy
values='field_count',
color='GenLU', # Optional coloring
title='Treemap: Dominant Crops by Land Use Category'
)
# Remove problematic 'customdata'
treemap.data[0].customdata = None
# ---- Layout ----
st.altair_chart(area_chart, use_container_width=True)
st.altair_chart(heatmap, use_container_width=True)
st.altair_chart(treemap, use_container_width=True)
# ---- Discussion Section ----
st.subheader("🧾 How to Use This Dashboard")app.py+23-12