krz/omaha-metro-blotter

Archive of police activity and ALPR surveillance across the Omaha metro. alpr archive omaha police surveillance

Commit 441d7dc25c

441d7dc25c04da4c3b747af04c21868745e7029e

parent: 1cc75d6c0e

Verified · cmc

cmc <hello@cleberg.net> · 2024-01-24 17:22 UTC

replace bar graph with table and update CSS

Layout: unified · split

app.py +14 −18
@@ -1,10 +1,10 @@
1from dash import Dash, html, dcc, callback, Output, Input
1from dash import Dash, html, dcc, callback, Output, Input, dash_table
22import plotly.express as px
33import pandas as pd
44import sqlite3
55
66# Connect to database and query all incidents
7connection = sqlite3.connect("../raw_data/ingress.db")
7connection = sqlite3.connect("./raw_data/ingress.db")
88cursor = connection.cursor()
99query = "SELECT * FROM incidents;"
1010df = pd.read_sql_query(query, connection).sort_values(by="description")
@@ -18,36 +18,32 @@ app.layout = html.Div(children = [
1818 html.H1(children="Omaha Police Invidents", style={"textAlign":"center"}),
1919 html.Div([
2020 html.H2(children="Totals per Category and Year", style={"textAlign":"center"}),
21 dcc.Dropdown(df.sort_values("description").description.unique(), "INJURY", id="bar-dropdown"),
22 dcc.Dropdown(df.sort_values("year").year.unique(), "2023", id="bar-year-dropdown"),
23 dcc.Graph(id="bar-graph")
24 ]),
25 html.Div([
21 dcc.Dropdown(df.sort_values("description").description.unique(), "INJURY", id="dropdown"),
22 dcc.Dropdown(df.sort_values("year").year.unique(), "2023", id="year-dropdown"),
23 html.Hr(),
24 dash_table.DataTable(data=df.to_dict("records"), page_size=5, id="table"),
2625 html.H2(children="Map of Incidents per Category and Year", style={"textAlign":"center"}),
27 dcc.Dropdown(df.sort_values("description").description.unique(), "INJURY", id="map-dropdown"),
28 dcc.Dropdown(df.sort_values("year").year.unique(), "2023", id="map-year-dropdown"),
2926 dcc.Graph(id="map-graph")
3027 ])
3128])
3229
33# Create bar graph
30# Create table
3431@callback(
35 Output("bar-graph", "figure"),
36 Input("bar-dropdown", "value"),
37 Input("bar-year-dropdown", "value")
32 Output("table", "data"),
33 Input("dropdown", "value"),
34 Input("year-dropdown", "value")
3835)
39def update_bar_graph(description, year):
36def update_table(description, year):
4037 dff = df[df.year == year]
41 dff = dff.value_counts(subset=["description"])
4238 dff = dff.reset_index()
4339 dff = dff[dff.description == description]
44 return px.bar(dff, x="description", y="count")
40 return dff.to_dict("records")
4541
4642# Create map
4743@callback(
4844 Output("map-graph", "figure"),
49 Input("map-dropdown", "value"),
50 Input("map-year-dropdown", "value")
45 Input("dropdown", "value"),
46 Input("year-dropdown", "value")
5147)
5248def update_map(description, year):
5349 dff = df[df.year == year]
assets/styles.css +4 −3
@@ -1,8 +1,9 @@
11body {
22 font-family: -apple-system, BlinkMacSystemFont, avenir next, avenir, segoe ui, helvetica neue, helvetica, Cantarell, Ubuntu, roboto, noto, arial, sans-serif;
3}
4
5#_dash-app-content {
63 max-width: 80vw;
74 margin: 2rem auto;
5}
6
7hr {
8 margin: 1rem auto;
89}
\ No newline at end of file