Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -202,18 +202,41 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 202 |
|
| 203 |
with gr.Column(scale=3):
|
| 204 |
gr.Markdown("### Visualizations")
|
| 205 |
-
|
| 206 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 207 |
|
|
|
|
| 208 |
update_button.click(
|
| 209 |
-
fn=
|
| 210 |
inputs=[metric_selector, start_date_picker, end_date_picker],
|
| 211 |
-
outputs=map_plot
|
| 212 |
)
|
| 213 |
-
|
| 214 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 215 |
inputs=[metric_selector, start_date_picker, end_date_picker],
|
| 216 |
-
outputs=ts_plot
|
| 217 |
)
|
| 218 |
|
| 219 |
with gr.Tab("Predictive Analytics"):
|
|
|
|
| 202 |
|
| 203 |
with gr.Column(scale=3):
|
| 204 |
gr.Markdown("### Visualizations")
|
| 205 |
+
# Initialize plots with default values
|
| 206 |
+
initial_map = create_choropleth_map('crime_total', min_date, max_date)
|
| 207 |
+
initial_ts = create_time_series_plot('crime_total', min_date, max_date)
|
| 208 |
+
|
| 209 |
+
map_plot = gr.Plot(value=initial_map)
|
| 210 |
+
ts_plot = gr.Plot(value=initial_ts)
|
| 211 |
+
|
| 212 |
+
# Function to update both plots
|
| 213 |
+
def update_plots(metric, start_date, end_date):
|
| 214 |
+
map_fig = create_choropleth_map(metric, start_date, end_date)
|
| 215 |
+
ts_fig = create_time_series_plot(metric, start_date, end_date)
|
| 216 |
+
return map_fig, ts_fig
|
| 217 |
|
| 218 |
+
# Update plots when button is clicked
|
| 219 |
update_button.click(
|
| 220 |
+
fn=update_plots,
|
| 221 |
inputs=[metric_selector, start_date_picker, end_date_picker],
|
| 222 |
+
outputs=[map_plot, ts_plot]
|
| 223 |
)
|
| 224 |
+
|
| 225 |
+
# Also update plots when any input changes
|
| 226 |
+
metric_selector.change(
|
| 227 |
+
fn=update_plots,
|
| 228 |
+
inputs=[metric_selector, start_date_picker, end_date_picker],
|
| 229 |
+
outputs=[map_plot, ts_plot]
|
| 230 |
+
)
|
| 231 |
+
start_date_picker.change(
|
| 232 |
+
fn=update_plots,
|
| 233 |
+
inputs=[metric_selector, start_date_picker, end_date_picker],
|
| 234 |
+
outputs=[map_plot, ts_plot]
|
| 235 |
+
)
|
| 236 |
+
end_date_picker.change(
|
| 237 |
+
fn=update_plots,
|
| 238 |
inputs=[metric_selector, start_date_picker, end_date_picker],
|
| 239 |
+
outputs=[map_plot, ts_plot]
|
| 240 |
)
|
| 241 |
|
| 242 |
with gr.Tab("Predictive Analytics"):
|