Applications

Row

Applications Map

Application Data

Row

Application Status

Priority Status

License Type

DBE Category

County

Licenses

Row

Licenses Map

Licenses Data

Row

License Status

Priority Status

License Type

DBE Category

County

Application Fee

License Fee

Authority Entities

Row

Authority Entities Map

Authority Entities Data

Business Interests Data

Row

License Status

Priority Status

License Type

DBE Category

County

---
title: "Cannabis Reparations"
output: 
  flexdashboard::flex_dashboard:
    social: [ "twitter", "facebook" ]
    source: embed
    theme: cosmo
    orientation: rows
    logo: cannabisreparations1.ico
---

```{r setup, include=FALSE}
library(flexdashboard)# interactive dashboard 
library(readxl) # import excel data set 
library(leaflet) #create interactive maps
library(tidyverse) # load core packages for data visualisation (dplyr:for data manipulation, tidyr:for data tidying, readr:for data import, purrr:for functional programming, tibble:for tibbles, a modern re-imagining of data frames, stringr:for strings, forcats:for factors)
library(DT) #Display data tables
library(crosstalk) # extends htmlwidgets
library(sf) #load shapefiles 
library(RColorBrewer) # color palaette
library(geojsonR) # need for geolines
library(shiny)
library(plyr)
library(plotly)
library(lubridate)
library(ggplot2) 
library(sp)
library(icon)
library(emojifont)
library(geosphere)


# Load Cannabis Data
Applications <- read_csv("Apps.csv")
License <- read_csv("Lic.csv")

Agents_Race <- read_csv("AR.csv")
Authority_Agents <- read_csv("AuA.csv")
Active_Agents <- read_excel("AA.xlsx")

Authority_Entities <- read_csv("AE.csv")
Business_Interets <- read_csv("BI.csv")
Geolines <- read_csv("Geolines.csv")

Applications$combo <- paste(Applications$Application_Status, Applications$Priority_Status,Applications$DBE_Category, Applications$License_Type, sep = "-")
Applications$Date_Created <- as.Date(Applications$Date_Created, format = "%m/%d/%y")
License$Date_Created <- as.Date(License$Date_Created, format = "%m/%d/%y")
License$Date_Submitted <- as.Date(License$Date_Submitted, format = "%m/%d/%y")
License$Date_Final_Licensure <- as.Date(License$Date_Final_Licensure, format = "%m/%d/%y")

# Load Shape Data 
ADI_Merged_shape <-st_read("Cannabis_ADI_shape/Cannabis_ADI_shape.shp", stringsAsFactors=FALSE, quiet=TRUE)
ADI_Merged_shape <-st_transform(ADI_Merged_shape,'+proj=longlat +datum=WGS84')



Agents_Race <- Agents_Race %>%
  mutate(ARboxinfo = paste0('Agent Race: ', Emoji, '
', 'Business Name: ', Business_Name, '
', 'Priority Status: ', Priority_Status, '
', 'License Type: ', License_Type, '
', 'DBE Category: ', DBE_Category, '
', 'Total Active Agents: ', Total_Race_Agents)) Active_Agents <- Active_Agents %>% mutate(AAboxinfo = paste0('Emoji: ', Emoji, '
', 'Business Role: ', Role, '
', 'Agent Gender: ', Gender, '
', 'Business Name: ', Business_Name, '
', 'Priority Status: ', Priority_Status, '
', 'License Type: ', License_Type, '
', 'DBE Category: ', DBE_Category, '
', 'Total Active Agents: ', Total_Active_Agents, '
')) Authority_Entities <- Authority_Entities %>% mutate(AutAboxinfo = paste0('Authority Name: ', Full_Name, '
', 'Role: ', Role, '
', 'Ownership: ', Ownership, '
', 'Control: ', Control, '
', 'Business Name: ', Business_Name, '
', 'License Status: ', License_Status, '
', 'Priority Status: ', Priority_Status, '
', 'License Type: ', License_Type, '
', 'DBE Category: ', DBE_Category, '
', 'Business Address: ', Business_Address, '
', 'Total Authority Agents: ', Total_Authority_Agents, '
')) Business_Interets <- Business_Interets %>% mutate(BIboxinfo = paste0('Authority Name: ', Full_Name, '
', 'Role: ', Role, '
', 'Business Name: ', Business_Name, '
', 'License Status: ', License_Status, '
', 'Priority Status: ', Priority_Status, '
', 'License Type: ', License_Type, '
', 'DBE Category: ', DBE_Category, '
', 'Business Address: ', Business_Address, '
', 'Total Authority Agents: ', Total_Authority_Agents, '
')) # Generate geolines data flows <- gcIntermediate(Geolines[,2:3], Geolines[,5:6], sp = TRUE, addStartEnd = TRUE) flows$Business_Name <- Geolines$business.name flows$Total_Agents <- Geolines$total.agents flows$Layer <- Geolines$layer flows$Ownership <- Geolines$ownership flows$Control <- Geolines$control # created shared data for geolines flows_sd <-SharedData$new(flows) sd_df <- SharedData$new(flows@data, group = flows_sd$groupName()) # create hover information for geolines hover <- paste0(flows_sd$data()$Business_Name, " to ", flows_sd$data()$Priority_Status, ': ', flows_sd$data()$DBE_Category, " | ", as.character(flows_sd$data()$Total_Agents)) # Create sharedDataFrames App_sd <-SharedData$new(Applications, group = "Applications") Lic_sd <-SharedData$new(License, group = "Licenses") AA_sd <-SharedData$new(Active_Agents, group = "Active") AR_sd <- SharedData$new(Agents_Race, group = "Race") AuA_sd <-SharedData$new(Authority_Agents, group = "Authority") AE_sd <-SharedData$new(Authority_Entities, group = "Entities") BI_sd <-SharedData$new(Business_Interets, group = "Interests") ``` Applications {data-orientation=rows data-icon="fa-cannabis"} ===================================== coloumn {data-width=300 .sidebar .colored} ----------------------------------------------------------------------- ### Application Filters ```{r App filters} # Filter input - Applications bscols( filter_select( id = "Business_Town", label = "Select Town", sharedData = App_sd, group = ~Business_Town, ), filter_select( id = "Business_County", label = "Select a County", sharedData = App_sd, group = ~Business_County, ) ) icon::fa_cannabis() bscols( filter_checkbox( id = "Priority_Status", label = "Prioirty Status", sharedData = App_sd, group = ~Priority_Status, inline = TRUE, allLevels = TRUE ), filter_checkbox( id = "Application_Status", label = "Application Status", sharedData = App_sd, group = ~Application_Status, inline = TRUE, allLevels = TRUE ) ) icon::fa_cannabis() filter_select("License_Type","License Type", App_sd, ~License_Type) icon::fa_cannabis() filter_slider("Total_Apps", "Total Applications", App_sd, ~Total_Apps, step = 1) icon::fa_cannabis() filter_select("DBE_Category","DBE Category", App_sd, ~DBE_Category) icon::fa_cannabis() filter_select("Business_Name","Search Business Name ", App_sd, ~Business_Name) ``` Row {data-width=950 .tabset .tabset-fade .colored } ----------------------------------------------------------------------- ### Applications Map ```{r App map} PSpal <- colorFactor(palette = 'Greens', domain = App_sd$Priority_Status) leaflet() %>% setView(-71.931180, 42.385453, zoom = 8) %>% addProviderTiles("CartoDB.DarkMatter", group = "Dark") %>% addProviderTiles("Esri.WorldGrayCanvas", group = "Grey") %>% addPolygons(data = ADI_Merged_shape, weight = .4, smoothFactor = 1, fillOpacity = ifelse(test = ADI_Merged_shape$Imp_C == "Impact", yes = 0.5, no = 0), color = "#878787", fillColor = "#17b502", label = ~Town_1, # name as a hover label group = "ADI") %>% addCircleMarkers(data = App_sd, lng = ~longitude, lat = ~latitude, popup = ~Appboxinfo, fillOpacity = ifelse(test = App_sd$data()$Priority_Status == "Economic Empowerment", yes = 1, no = 0), fillColor = "green", color = ~PSpal(Priority_Status), radius = 1, group = "Applications") %>% addLayersControl(overlayGroups = c("ADI","Applications"), baseGroups = c("Dark","Grey", "Applications"), options = layersControlOptions(collapsed = FALSE)) %>% addMeasure() ``` ### Application Data ```{r} datatable(App_sd, extensions= c('Buttons', "Scroller"), class="compact", width="100%", rownames = FALSE, options=list( dom = 'Blfrtip', deferRender=TRUE, scrollY=300, scroller=TRUE, columnDefs = list(list(visible=FALSE, targets=c(8,9))), buttons = list(I('colvis'), 'csv', 'excel'))) ``` Row {data-height=250 .tabset .tabset-fade .colored } ----------------------------------------------------------------------- ### Application Status ```{r} ggplotly(ggplot(App_sd, aes(Total_Apps, fill = factor(Application_Status))) + geom_bar() + coord_flip() ) ``` ### Priority Status ```{r} ggplotly(ggplot(App_sd, aes(Total_Apps, fill = factor(Priority_Status))) + geom_bar() + coord_flip() ) ``` ### License Type ```{r} ggplotly(ggplot(App_sd, aes(Total_Apps, fill = factor(License_Type))) + geom_bar() + coord_flip()) ``` ### DBE Category ```{r} ggplotly(ggplot(App_sd, aes(Total_Apps, fill = factor(DBE_Category))) + geom_bar() + coord_flip()) ``` ### County ```{r} ggplotly(ggplot(App_sd, aes(Total_Apps, fill = factor(Business_County))) + geom_bar() + coord_flip()) ``` Licenses {data-orientation=Columns data-icon="fa-cannabis"} ===================================== coloumn {data-width=300 .sidebar .colored} ----------------------------------------------------------------------- ### License Filters ```{r Lic filters} # Filter input - Applications icon::fa_cannabis() bscols( filter_select( id = "Business_Town", label = "Select Town", sharedData = Lic_sd, group = ~Business_Town, ), filter_select( id = "Business_County", label = "Select a County", sharedData = Lic_sd, group = ~Business_County, ) ) icon::fa_cannabis() bscols( filter_checkbox( id = "Priority_Status", label = "Prioirty Status", sharedData = Lic_sd, group = ~Priority_Status, inline = TRUE, allLevels = TRUE ), filter_checkbox( id = "License_Status", label = "License Status", sharedData = Lic_sd, group = ~License_Status, inline = TRUE, allLevels = TRUE ) ) icon::fa_cannabis() filter_select("DBE_Category","DBE Category", Lic_sd, ~DBE_Category) icon::fa_cannabis() filter_slider("Total_Licenses", "Total Licenses", Lic_sd, ~Total_Licenses, step = 1) ``` Row {data-width=950 .tabset .tabset-fade .colored } ----------------------------------------------------------------------- ### Licenses Map ```{r Lic map} pal4 <- colorFactor( palette = 'Spectral', levels=Lic_sd$data()$License_Type, ordered=FALSE ) leaflet() %>% setView(-71.931180, 42.385453, zoom = 7) %>% addProviderTiles("CartoDB.DarkMatter", group = "Dark") %>% addProviderTiles("Esri.WorldGrayCanvas", group = "Grey") %>% addPolygons(data = ADI_Merged_shape, weight = .4, smoothFactor = 1, fillOpacity = ifelse(test = ADI_Merged_shape$Imp_C == "Impact", yes = 0.5, no = 0), color = "#878787", fillColor = "#17b502", label = ~Town_1, # name as a hover label group = "ADI") %>% addCircleMarkers(data = Lic_sd, lng = ~Lon, lat = ~Lat, popup = ~Licboxinfo, color = ~pal4(License_Type), radius = 1, group = "Licenses") %>% addLayersControl(overlayGroups = c("ADI","Licenses"), baseGroups = c("Dark","Grey", "Licenses"), options = layersControlOptions(collapsed = FALSE)) %>% addMeasure() ``` ### Licenses Data ```{r} datatable(Lic_sd, extensions= c('Buttons', "Scroller"), class="compact", width="100%", rownames = FALSE, options=list( dom = 'Blfrtip', deferRender=TRUE, scrollY=300, scroller=TRUE, columnDefs = list(list(visible=FALSE, targets=c(8,9))), buttons = list(I('colvis'), 'csv', 'excel'))) ``` Row {data-height=250 .tabset .tabset-fade .colored } ----------------------------------------------------------------------- ### License Status ```{r} ggplotly(ggplot(Lic_sd, aes(Total_Licenses, fill = factor(License_Status))) + geom_bar() + coord_flip() ) ``` ### Priority Status ```{r} ggplotly(ggplot(Lic_sd, aes(Total_Licenses, fill = factor(Priority_Status))) + geom_bar() + coord_flip() ) ``` ### License Type ```{r} ggplotly(ggplot(Lic_sd, aes(Total_Licenses, fill = factor(License_Type))) + geom_bar() + coord_flip()) ``` ### DBE Category ```{r} ggplotly(ggplot(Lic_sd, aes(Total_Licenses, fill = factor(DBE_Category))) + geom_bar() + coord_flip()) ``` ### County ```{r} ggplotly(ggplot(Lic_sd, aes(Total_Licenses, fill = factor(Business_County))) + geom_bar() + coord_flip()) ``` ### Application Fee ```{r} ggplotly(ggplot(Lic_sd, aes(Application_Fee, fill = factor(Business_County))) + geom_bar() + coord_flip()) plot_ly(Lic_sd, labels = ~ Business_Town, values = ~ Application_Fee, type = 'pie', textposition = 'inside', textinfo = 'label+percent') ``` ### License Fee ```{r} plot_ly(Lic_sd, labels = ~ Business_Town, values = ~ Lic_Fee, type = 'pie', textposition = 'inside', textinfo = 'label+percent') ``` Authority Entities {data-orientation=Columns data-icon="fa-cannabis"} ===================================== coloumn {data-width=300 .sidebar .tabset .tabset-fade .colored} ----------------------------------------------------------------------- ### Authority Entities Filters ```{r AE filters} # Filter input - Applications icon::fa_cannabis() bscols( filter_select( id = "Business_Town", label = "Select Town", sharedData = AuA_sd, group = ~Business_Town, ), filter_select( id = "Business_County", label = "Select a County", sharedData = AuA_sd, group = ~Business_County, ) ) icon::fa_cannabis() bscols( filter_checkbox( id = "Priority_Status", label = "Prioirty Status", sharedData = AuA_sd, group = ~Priority_Status, inline = TRUE, allLevels = TRUE ), filter_checkbox( id = "License_Status", label = "License Status", sharedData = AuA_sd, group = ~License_Status, inline = TRUE, allLevels = TRUE ) ) icon::fa_cannabis() filter_select("DBE_Category","DBE Category", AuA_sd, ~DBE_Category) icon::fa_cannabis() filter_slider("Total_Authority_Agents", "Total Authority Agents", AuA_sd, ~Total_Authority_Agents, step = 5) icon::fa_cannabis() filter_slider("Ownership", "% Ownership", AuA_sd, ~Ownership, step = 10) icon::fa_cannabis() filter_slider("Control", "% Controls", AuA_sd, ~Control, step = 10) icon::fa_cannabis() filter_checkbox("Layer", "Layer", sd_df, ~Layer, allLevels = TRUE) filter_checkbox("Ownership", "Ownership", sd_df, ~Ownership, allLevels = TRUE) icon::fa_cannabis() filter_checkbox("Control", "Control", sd_df, ~Control, allLevels = TRUE) ``` Row {data-width=950 .tabset .tabset-fade .colored } ----------------------------------------------------------------------- ### Authority Entities Map ```{r AEBI map} pal6 <- colorFactor( palette = 'Spectral', levels=AE_sd$data()$Role, ordered=FALSE ) leaflet() %>% setView(-71.931180, 42.385453, zoom = 7) %>% addProviderTiles("CartoDB.DarkMatter", group = "Dark") %>% addProviderTiles("Esri.WorldGrayCanvas", group = "Grey") %>% addPolygons(data = ADI_Merged_shape, weight = .4, smoothFactor = 1, fillOpacity = ifelse(test = ADI_Merged_shape$Imp_C == "Impact", yes = 0.5, no = 0), color = "#878787", fillColor = "#17b502", label = ~Town_1, # name as a hover label group = "ADI") %>% addCircleMarkers(data = AE_sd, lng = ~Lon, lat = ~Lat, color = ~pal6(Role), radius = ~1, group = "Entities") %>% addCircleMarkers(data = BI_sd, lng = ~Lon, lat = ~Lat, color = ~pal6(Role), radius = ~1, group = "Interests") %>% addPolylines(data = flows_sd, weight = flows_sd$data()$Total_Agents/5, label = hover, group = "BI", color="#00b3ff") %>% addCircleMarkers(Geolines$end.latitude, Geolines$end.longitude, color="orange", radius=Geolines$ownership/5, group= "Interests") %>% addCircleMarkers(Geolines$start.latitude, Geolines$start.longitude, color="orange", radius=Geolines$control/5, group = "Interests") %>% addLayersControl(overlayGroups = c("ADI","Entities", "Interests"), baseGroups = c("Dark","Grey", "Entities", "Interests"), options = layersControlOptions(collapsed = FALSE)) %>% addMeasure() ``` ### Authority Entities Data ```{r} datatable(AE_sd, extensions= c('Buttons', "Scroller"), class="compact", width="100%", rownames = FALSE, options=list( dom = 'Blfrtip', deferRender=TRUE, scrollY=300, scroller=TRUE, columnDefs = list(list(visible=FALSE, targets=c(8,9))), buttons = list(I('colvis'), 'csv', 'excel'))) ``` ### Business Interests Data ```{r} datatable(BI_sd, extensions= c('Buttons', "Scroller"), class="compact", width="100%", rownames = FALSE, options=list( dom = 'Blfrtip', deferRender=TRUE, scrollY=300, scroller=TRUE, columnDefs = list(list(visible=FALSE, targets=c(8,9))), buttons = list(I('colvis'), 'csv', 'excel'))) ``` Row {data-height=250 .tabset .tabset-fade .colored } ----------------------------------------------------------------------- ### License Status ```{r} ggplotly(ggplot(AE_sd, aes(Total_Authority_Agents, fill = factor(License_Status))) + geom_bar() + coord_flip() ) ``` ### Priority Status ```{r} ggplotly(ggplot(AE_sd, aes(Total_Authority_Agents, fill = factor(Priority_Status))) + geom_bar() + coord_flip() ) ``` ### License Type ```{r} ggplotly(ggplot(AE_sd, aes(Total_Authority_Agents, fill = factor(License_Type))) + geom_bar() + coord_flip()) ``` ### DBE Category ```{r} ggplotly(ggplot(AE_sd, aes(Total_Authority_Agents, fill = factor(DBE_Category))) + geom_bar() + coord_flip()) ``` ### County ```{r} ggplotly(ggplot(AE_sd, aes(Total_Authority_Agents, fill = factor(Business_County))) + geom_bar() + coord_flip()) ```