alidenewade commited on
Commit
b7daf02
·
verified ·
1 Parent(s): 61e6cdd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -34
app.py CHANGED
@@ -81,7 +81,7 @@ def create_choropleth_map(metric, start_date, end_date):
81
  cmap='viridis',
82
  legend_kwds={'label': f"Total {metric.replace('_', ' ').title()}",
83
  'orientation': "horizontal"})
84
- ax.set_title(f'Spatial Distribution of {metric.replace("_", " ").title()}', fontsize=15)
85
  ax.set_axis_off()
86
  plt.tight_layout()
87
  return fig
@@ -195,48 +195,25 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
195
  min_date = panel_df['month'].min().to_pydatetime()
196
  max_date = panel_df['month'].max().to_pydatetime()
197
 
198
- start_date_picker = gr.DateTime(label="Start Date", value=min_date, include_time=False)
199
- end_date_picker = gr.DateTime(label="End Date", value=max_date, include_time=False)
200
 
201
  update_button = gr.Button("Update Dashboard")
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"):
@@ -281,4 +258,4 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
281
  )
282
 
283
  if __name__ == "__main__":
284
- demo.launch()
 
81
  cmap='viridis',
82
  legend_kwds={'label': f"Total {metric.replace('_', ' ').title()}",
83
  'orientation': "horizontal"})
84
+ ax.set_title(f'Spatial Distribution of {metric.replace("_', ' ').title()}', fontsize=15)
85
  ax.set_axis_off()
86
  plt.tight_layout()
87
  return fig
 
195
  min_date = panel_df['month'].min().to_pydatetime()
196
  max_date = panel_df['month'].max().to_pydatetime()
197
 
198
+ start_date_picker = gr.DatePicker(label="Start Date", value=min_date)
199
+ end_date_picker = gr.DatePicker(label="End Date", value=max_date)
200
 
201
  update_button = gr.Button("Update Dashboard")
202
 
203
  with gr.Column(scale=3):
204
  gr.Markdown("### Visualizations")
205
+ map_plot = gr.Plot()
206
+ ts_plot = gr.Plot()
 
 
 
 
 
 
 
 
 
 
207
 
 
208
  update_button.click(
209
+ fn=create_choropleth_map,
 
 
 
 
 
 
 
 
 
 
 
 
210
  inputs=[metric_selector, start_date_picker, end_date_picker],
211
+ outputs=map_plot
212
  )
213
+ update_button.click(
214
+ fn=create_time_series_plot,
215
  inputs=[metric_selector, start_date_picker, end_date_picker],
216
+ outputs=ts_plot
217
  )
218
 
219
  with gr.Tab("Predictive Analytics"):
 
258
  )
259
 
260
  if __name__ == "__main__":
261
+ demo.launch()