Created
June 5, 2017 02:59
-
-
Save DTAIEB/b0a8428edc7f20990b159b7847bb37d7 to your computer and use it in GitHub Desktop.
PixieApp dashboard for the Data Science Bootcamp with PixieDust
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pixiedust.display.app import * | |
from pixiedust.apps.mapboxBase import MapboxBase | |
@PixieApp | |
class SFDashboard(MapboxBase): | |
def setup(self): | |
self.mapJSONOptions = { | |
"mapboxtoken": "XXXX", | |
"chartsize": "90", | |
"aggregation": "SUM", | |
"rowCount": "500", | |
"handlerId": "mapView", | |
"rendererId": "mapbox", | |
"valueFields": "IncidntNum", | |
"keyFields": "X,Y", | |
"basemap": "light-v9" | |
} | |
self.setLayers([ | |
{ | |
"name": "Speeding", | |
"url": "https://data.sfgov.org/api/geospatial/mfjz-pnye?method=export&format=GeoJSON" | |
}, | |
{ | |
"name": "Traffic calming", | |
"url": "https://data.sfgov.org/api/geospatial/ddye-rism?method=export&format=GeoJSON", | |
"type": "symbol", | |
"layout": { | |
"icon-image": "police-15", | |
"icon-size": 1.5 | |
} | |
}, | |
{ | |
"name": "Police Districts", | |
"url": "https://data.sfgov.org/api/geospatial/wkhw-cjsf?method=export&format=GeoJSON" | |
}, | |
{ | |
"name": "Crimes", | |
"url": "https://data.sfgov.org/api/geospatial/ms8q-rzqw?method=export&format=GeoJSON", | |
"paint":{ | |
"fill-color": "rgba(255,182,193,0.5)" | |
} | |
} | |
]) | |
def formatOptions(self,options): | |
return ';'.join(["{}={}".format(key,value) for (key, value) in iteritems(options)]) | |
@route() | |
def mainScreen(self): | |
return """ | |
<div class="well"> | |
<center><span style="font-size:x-large">Analyzing San Francisco Public Safety data with PixieDust</span></center> | |
<center><span style="font-size:large"><a href="https://datasf.org/opendata" target="new">https://datasf.org/opendata</a></span></center> | |
</div> | |
<div class="row"> | |
<div class="form-group col-sm-2" style="padding-right:10px;"> | |
<div><strong>Layers</strong></div> | |
{% for layer in this.layers %} | |
<div class="rendererOpt checkbox checkbox-primary"> | |
<input type="checkbox" pd_refresh="map{{prefix}}" pd_script="self.toggleLayer({{loop.index0}})"> | |
<label>{{layer["name"]}}</label> | |
</div> | |
{%endfor%} | |
</div> | |
<div class="form-group col-sm-10"> | |
<div id="map{{prefix}}" pd_entity pd_options="{{this.formatOptions(this.mapJSONOptions)}}"/> | |
</div> | |
</div> | |
""" | |
SFDashboard().run(accidents,runInDialog="false") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment