diff options
author | Christian Cleberg <hello@cleberg.net> | 2024-01-24 11:22:32 -0600 |
---|---|---|
committer | Christian Cleberg <hello@cleberg.net> | 2024-01-24 11:22:32 -0600 |
commit | 441d7dc25c04da4c3b747af04c21868745e7029e (patch) | |
tree | a5625a5a1710fd756d926203104bd5b80be14ac6 /app.py | |
parent | 1cc75d6c0e445b0d53c036d500d76f9074aec81a (diff) | |
download | omaha-incidents-441d7dc25c04da4c3b747af04c21868745e7029e.tar.gz omaha-incidents-441d7dc25c04da4c3b747af04c21868745e7029e.tar.bz2 omaha-incidents-441d7dc25c04da4c3b747af04c21868745e7029e.zip |
replace bar graph with table and update CSS
Diffstat (limited to 'app.py')
-rw-r--r-- | app.py | 32 |
1 files changed, 14 insertions, 18 deletions
@@ -1,10 +1,10 @@ -from dash import Dash, html, dcc, callback, Output, Input +from dash import Dash, html, dcc, callback, Output, Input, dash_table import plotly.express as px import pandas as pd import sqlite3 # Connect to database and query all incidents -connection = sqlite3.connect("../raw_data/ingress.db") +connection = sqlite3.connect("./raw_data/ingress.db") cursor = connection.cursor() query = "SELECT * FROM incidents;" df = pd.read_sql_query(query, connection).sort_values(by="description") @@ -18,36 +18,32 @@ app.layout = html.Div(children = [ html.H1(children="Omaha Police Invidents", style={"textAlign":"center"}), html.Div([ html.H2(children="Totals per Category and Year", style={"textAlign":"center"}), - dcc.Dropdown(df.sort_values("description").description.unique(), "INJURY", id="bar-dropdown"), - dcc.Dropdown(df.sort_values("year").year.unique(), "2023", id="bar-year-dropdown"), - dcc.Graph(id="bar-graph") - ]), - html.Div([ + dcc.Dropdown(df.sort_values("description").description.unique(), "INJURY", id="dropdown"), + dcc.Dropdown(df.sort_values("year").year.unique(), "2023", id="year-dropdown"), + html.Hr(), + dash_table.DataTable(data=df.to_dict("records"), page_size=5, id="table"), html.H2(children="Map of Incidents per Category and Year", style={"textAlign":"center"}), - dcc.Dropdown(df.sort_values("description").description.unique(), "INJURY", id="map-dropdown"), - dcc.Dropdown(df.sort_values("year").year.unique(), "2023", id="map-year-dropdown"), dcc.Graph(id="map-graph") ]) ]) -# Create bar graph +# Create table @callback( - Output("bar-graph", "figure"), - Input("bar-dropdown", "value"), - Input("bar-year-dropdown", "value") + Output("table", "data"), + Input("dropdown", "value"), + Input("year-dropdown", "value") ) -def update_bar_graph(description, year): +def update_table(description, year): dff = df[df.year == year] - dff = dff.value_counts(subset=["description"]) dff = dff.reset_index() dff = dff[dff.description == description] - return px.bar(dff, x="description", y="count") + return dff.to_dict("records") # Create map @callback( Output("map-graph", "figure"), - Input("map-dropdown", "value"), - Input("map-year-dropdown", "value") + Input("dropdown", "value"), + Input("year-dropdown", "value") ) def update_map(description, year): dff = df[df.year == year] |