11"""Instantiate a Dash app."""
2- import numpy as np
3- import pandas as pd
42import dash
5- import dash_table
6- import dash_html_components as html
73import dash_core_components as dcc
4+ import dash_html_components as html
5+ import dash_table
6+ import numpy as np
7+ import pandas as pd
8+
89from .data import create_dataframe
910from .layout import html_layout
1011
@@ -13,11 +14,11 @@ def init_dashboard(server):
1314 """Create a Plotly Dash dashboard."""
1415 dash_app = dash .Dash (
1516 server = server ,
16- routes_pathname_prefix = ' /dashapp/' ,
17+ routes_pathname_prefix = " /dashapp/" ,
1718 external_stylesheets = [
18- ' /static/dist/css/styles.css' ,
19- ' https://fonts.googleapis.com/css?family=Lato'
20- ]
19+ " /static/dist/css/styles.css" ,
20+ " https://fonts.googleapis.com/css?family=Lato" ,
21+ ],
2122 )
2223
2324 # Load DataFrame
@@ -28,38 +29,41 @@ def init_dashboard(server):
2829
2930 # Create Layout
3031 dash_app .layout = html .Div (
31- children = [dcc .Graph (
32- id = 'histogram-graph' ,
33- figure = {
34- 'data' : [{
35- 'x' : df ['complaint_type' ],
36- 'text' : df ['complaint_type' ],
37- 'customdata' : df ['key' ],
38- 'name' : '311 Calls by region.' ,
39- 'type' : 'histogram'
40- }],
41- 'layout' : {
42- 'title' : 'NYC 311 Calls category.' ,
43- 'height' : 500 ,
44- 'padding' : 150
45- }
46- }),
47- create_data_table (df )
32+ children = [
33+ dcc .Graph (
34+ id = "histogram-graph" ,
35+ figure = {
36+ "data" : [
37+ {
38+ "x" : df ["complaint_type" ],
39+ "text" : df ["complaint_type" ],
40+ "customdata" : df ["key" ],
41+ "name" : "311 Calls by region." ,
42+ "type" : "histogram" ,
43+ }
44+ ],
45+ "layout" : {
46+ "title" : "NYC 311 Calls category." ,
47+ "height" : 500 ,
48+ "padding" : 150 ,
49+ },
50+ },
51+ ),
52+ create_data_table (df ),
4853 ],
49- id = ' dash-container'
54+ id = " dash-container" ,
5055 )
5156 return dash_app .server
5257
5358
5459def create_data_table (df ):
5560 """Create Dash datatable from Pandas DataFrame."""
5661 table = dash_table .DataTable (
57- id = ' database-table' ,
62+ id = " database-table" ,
5863 columns = [{"name" : i , "id" : i } for i in df .columns ],
59- data = df .to_dict (' records' ),
64+ data = df .to_dict (" records" ),
6065 sort_action = "native" ,
61- sort_mode = ' native' ,
62- page_size = 300
66+ sort_mode = " native" ,
67+ page_size = 300 ,
6368 )
6469 return table
65-
0 commit comments