jinwenz2 commited on
Commit
48eb1fb
·
verified ·
1 Parent(s): 7bec988

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +10 -14
src/streamlit_app.py CHANGED
@@ -262,16 +262,12 @@ top_10_crimes = df['crm_cd_desc'].value_counts().nlargest(10).index.tolist()
262
  # Filter the main DataFrame to include only top 10 crimes
263
  df_top = df[df['crm_cd_desc'].isin(top_10_crimes)]
264
 
265
- # Create the dropdown.
266
- crime_dropdown = ipywidgets.Dropdown(
267
- options= sorted(top_10_crimes),
268
- description="Crime Type:")
269
-
270
- # Creat dropdown menu.
271
- year_dropdown = ipywidgets.Dropdown(
272
- options= sorted(df['year'].unique()),
273
- description='Year:'
274
- )
275
 
276
  # Create the map.
277
  def crime_map(year, crime):
@@ -289,10 +285,10 @@ def crime_map(year, crime):
289
  ax.set_xlabel("Longitude")
290
  ax.set_ylabel("Latitude")
291
  plt.grid(True)
292
- plt.show()
293
-
294
- # Displat the plot.
295
- ipywidgets.interact(crime_map, year=year_dropdown, crime=crime_dropdown)
296
 
297
  # Define what each menu option does
298
  if menu == "Home":
 
262
  # Filter the main DataFrame to include only top 10 crimes
263
  df_top = df[df['crm_cd_desc'].isin(top_10_crimes)]
264
 
265
+
266
+ # Creat dropdown menu
267
+ years = sorted(df['year'].unique())
268
+ year_dropdown = st.selectbox("Year: ", years)
269
+ crime_dropdown = st.selectbox("Crime Type: ", top_10_crimes)
270
+
 
 
 
 
271
 
272
  # Create the map.
273
  def crime_map(year, crime):
 
285
  ax.set_xlabel("Longitude")
286
  ax.set_ylabel("Latitude")
287
  plt.grid(True)
288
+ st.pyplot(fig)
289
+
290
+ # Call the function with selected values
291
+ crime_map(year_dropdown, crime_dropdown)
292
 
293
  # Define what each menu option does
294
  if menu == "Home":