Dashboard

Cambridge Board of Zoning Appeals Requests

Variances

Special Permits

Variance / Special permits

Row

Row

About

About this map

This map shows Cambridge variances and special permits with status of under review, approved, denied or withdrawn and application dates in 2015-2017.

Data is from the City of Cambridge Board of Zoning Appeal Requests (as of 2017-05-02), mapped by Kent S Johnson.

Copyright 2017 Kent S Johnson Creative Commons License 2017-05-02

---
title: "Cambridge Board of Zoning Appeals Requests 2015-2017"
output: 
  flexdashboard::flex_dashboard:
    orientation: rows
    vertical_layout: fill
    source_code: embed
    theme: spacelab
    css: style.css
---

```{r parameters, echo=FALSE,include=FALSE,message=FALSE}
library(crosstalk)
library(dplyr)
library(flexdashboard)
library(htmltools)
library(httr)
library(leaflet)
library(lubridate)
#library(raster) # Don't use as library, it breaks dplyr::select
library(readr)
library(sp)
library(stringr)
library(summarywidget)

source('../CODutil.R')
knitr::opts_chunk$set(echo=FALSE, fig.width=10, fig.height=6, results='asis',
                      comment=NA, warning=FALSE, message=FALSE)
```

Dashboard
==========

Cambridge Board of Zoning Appeals Requests {data-height=160}
------------------------------------------

```{r data}
city = raster::shapefile('../BOUNDARY_CityBoundary.shp/BOUNDARY_CityBoundary.shp') %>% 
  spTransform(CRS("+init=EPSG:4326"))
#bza = read_csv('../Board_of_Zoning_Appeal_Requests.csv') %>% 
# Use httr to get the data so we can retrieve the Last-Modified date
r = GET('http://data.cambridgema.gov/api/views/urfm-usws/rows.csv?accessType=DOWNLOAD&api_foundry=true')
bza_date = headers(r)$`last-modified` %>% parse_http_date %>% with_tz('America/New_York')
bza = content(r) %>% 
    mutate(Year = year(mdy(`Application Date`, tz='America/New_York'))) %>% 
  filter(Year >= 2015) %>% parse_location
```

```{r sharedData}
maybe = function(item, head=NULL, brk=TRUE)
  if(is.null(item) || is.na(item) || (is.numeric(item) && item==0)) '' else tagList((if(brk) br()), head, item)

# Link to Google map with streetview picture as content
make_streetview = function(loc) {
  a(img(src=HTML(paste0('https://maps.googleapis.com/maps/api/streetview?size=300x200&location=', 
                        loc,
                    ',%20Cambridge,%20MA&key=AIzaSyCGLmZrfyiAzsx0nDfG0e2Dkdi8Ot5wHtM'))),
    href=HTML(paste0('https://www.google.com/maps/place/', loc, ',%20Cambridge,%20MA')),
    target='_blank')
}

make_popups = function(d)
  lapply(1:nrow(d),
       function(i) {
         row = d[i,]
         HTML(as.character(p(
           strong(row$Location), br(),
           a(href=paste0("http://www.cambridgema.gov/Search?q=", 
                         row$`Application Number`), 
             target="_blank", row$`Application Number`), br(),
           row$`Type of Request`, ', ',
           row$`Status of Request`, br(),
           maybe(row$`Summary For Publication`),
           make_streetview(row$Location)
         )))
         })

bza$popups = make_popups(bza)
bza$labels = paste(bza$`Type of Request`, bza$`Status of Request`, sep=', ')
color_fun = colorFactor(c('blue', 'red', 'purple'), unique(bza$`Type of Request`))

bza_shared = SharedData$new(bza)
```

```{r}

div(class="section level3 bg-primary", style="flex: 960 960 0px;",
div(class="inner",
p(class="value", summarywidget(bza_shared, selection=~`Type of Request`=='Variance'), span(class="caption", "Variances"))))

div(class="section level3 bg-primary", style="flex: 960 960 0px;",
div(class="inner",
p(class="value", summarywidget(bza_shared, selection=~`Type of Request`=='Special Permit'), span(class="caption", "Special Permits"))))

div(class="section level3 bg-primary", style="flex: 960 960 0px;",
div(class="inner",
p(class="value", summarywidget(bza_shared, selection=~`Type of Request`=='Variance/Special Permit'), span(class="caption", "Variance / Special permits"))))
```

Row {data-height=180}
----------------

```{r}
map = leaflet(width='100%') %>% addProviderTiles('Esri.WorldTopoMap') %>% 
  setView(-71.1129096, 42.3783904, zoom = 14) %>% 
  addPolygons(data=city, fill=FALSE, color='steelblue', weight=3) %>% 
  addCircleMarkers(data=bza_shared, color=~color_fun(`Type of Request`),
                         radius=5, stroke=FALSE, opacity=0.6, fillOpacity=0.6,
            label=bza$labels, popup=bza$popups, group=~`Status of Request`) %>% 
  #addLayersControl(overlayGroups=sort(unique(bza$`Status of Request`))) %>% 
  addLegend(position='bottomleft', pal=color_fun, values=bza$`Type of Request`)
```

### 

```{r}
 filter_checkbox('Year', 'Year', bza_shared, ~Year, inline=TRUE)
```

### 

```{r}
 filter_checkbox('Type', 'Type of request', bza_shared, ~`Type of Request`, inline=TRUE)
```

### 

```{r}
 filter_checkbox('Status', 'Status', bza_shared, ~`Status of Request`, inline=TRUE)

```

Row {data-height=1000}
----------------


```{r}
map

```

About
================

### About this map

This map shows Cambridge variances and special permits with status of 
under review, approved, denied or withdrawn and application dates in 2015-2017.

Data is from the [City of Cambridge](http://cambridgema.gov) [Board of Zoning Appeal Requests](https://data.cambridgema.gov/Inspectional-Services/Board-of-Zoning-Appeal-Requests/urfm-usws) (as of `r format(bza_date, '%Y-%m-%d')`), mapped by Kent S Johnson. 

Copyright 2017 Kent S Johnson

  Creative Commons License
  `r Sys.Date()`