Spaces:
Build error
Build error
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +18 -16
src/streamlit_app.py
CHANGED
|
@@ -269,23 +269,25 @@ fig.update_layout(
|
|
| 269 |
# 4. Render
|
| 270 |
st.plotly_chart(fig, use_container_width=True)
|
| 271 |
|
| 272 |
-
#
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
)
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
|
|
|
|
|
|
|
|
|
| 287 |
)
|
| 288 |
-
fig.update_layout(margin=dict(t=50, l=25, r=25, b=25))
|
| 289 |
st.plotly_chart(fig, use_container_width=True)
|
| 290 |
|
| 291 |
|
|
|
|
| 269 |
# 4. Render
|
| 270 |
st.plotly_chart(fig, use_container_width=True)
|
| 271 |
|
| 272 |
+
# Prepare source/target/value lists
|
| 273 |
+
grouped = tm.copy()
|
| 274 |
+
regions = list(grouped["RegionName"].unique())
|
| 275 |
+
crimes = list(grouped["crm_cd_desc"].unique())
|
| 276 |
+
|
| 277 |
+
labels = regions + crimes
|
| 278 |
+
source = grouped["RegionName"].apply(lambda x: labels.index(x))
|
| 279 |
+
target = grouped["crm_cd_desc"].apply(lambda x: labels.index(x))
|
| 280 |
+
value = grouped["Count"]
|
| 281 |
+
|
| 282 |
+
fig = go.Figure(data=[go.Sankey(
|
| 283 |
+
node=dict(label=labels, pad=15, thickness=20),
|
| 284 |
+
link=dict(source=source, target=target, value=value)
|
| 285 |
+
)])
|
| 286 |
+
fig.update_layout(
|
| 287 |
+
title_text="Sankey: Region → Crime Type Flows",
|
| 288 |
+
font_size=10,
|
| 289 |
+
margin=dict(t=50, l=25, r=25, b=25)
|
| 290 |
)
|
|
|
|
| 291 |
st.plotly_chart(fig, use_container_width=True)
|
| 292 |
|
| 293 |
|