Background

Column

Data Pools

Active School Vacancies

252

Active Applicants

9764

Candidates of Color

Column

Hiring Data

Teachers Hired to date

456

Teachers of Color Hired to date

214

Teachers of Color Hired

Row

Recommendations

Teachers of Color Hired at Top Schools

41

Teachers of Color Hired at Needs Improvement Schools

22

Potential Teachers of Color

Vacancies Pool

Column

School Vacancies

Map

Row

School

Autonomy Status

Applicant Pool

Column

Application Type

Data Table

Row

Category

Ethnicity

Type

Schools

Autonomy Status

Candidate Pool

Column

Candidates of Color

Map

Data Table

Hire

Column

Teacher of Color Hires

Hires Map

Data Table

Row

Category

Ethnicity

Type

Schools

Autonomy Status

School Performance

Row

Top Performers

Schools with the highest number of Teacher of Color Hires

Row

Needs Improvement

Schools with the lowest number of Teacher of Color Hires

Recommendations

Teacher of Color Hires

Potential number of teachers of color
---
title: "BPS SY23-24 Hiring Data"
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    theme: cosmo
    vertical_layout: fill
    source: embed
---

```{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(shiny)
library(plyr)
library(plotly)
library(lubridate)
library(ggplot2)
library(ggmap)
library(sp)
library(mapview)
library(emojifont)
library(geosphere)
library(moonBook) # For Donuts Chart
library(webr) # For Donuts Chart
library(shiny)
library(d3scatter)
library(summarywidget)
```

```{r data, include=FALSE}

# Load candidate information and teaching job postings data
candidates <- read.csv("Candidates.csv")
applications <-read.csv("Applications.csv")
vacancies <- read.csv("Vacancies.csv")
schools <- read.csv("School_Data.csv")

# Convert  the Application Date column from a character data type to a Date data type
applications <- applications %>%mutate(Application.Date = as.Date(Application.Date, format = "%m/%d/%Y"))

#Subset data to only keep needed columns
vacancies_sub <- subset(vacancies, select = c("PositionID", "Job_Title", "DeptID","Status"))
applications_sub <- subset(applications, select = c("ApplicantProfile.ID","Application.Date","Application.Status","Posting.ID"))

# Rename column to match school data
vacancies_sub <- vacancies_sub %>% rename(`Dept.ID` = DeptID) 
vacancies_sub <- vacancies_sub %>% rename(`Posting.ID` = PositionID)

# Rename Ethnicity for better visualization
candidates <-candidates %>%
  mutate(Ethnicity = ifelse(Ethnicity == "African-American/Black (Non Hispanic)", "African-American/Black", Ethnicity)) %>%
  mutate(Ethnicity = ifelse(Ethnicity == "White (Non Hispanic)", "White", Ethnicity))

# Combine school demographic data with teacher vacancies data
schools_vacancies <- merge(schools, vacancies_sub, by = "Dept.ID")

# Applications by School
school_apps <- merge(vacancies_sub, applications_sub, by = "Posting.ID") 

schools_apps <- left_join(school_apps, schools, by = "Dept.ID")

# Candidates by School
school_canidates <- merge(candidates, schools_apps, by = "ApplicantProfile.ID")

# Applications by School and Race
school_applications <- school_canidates

# Create Teacher of Color Category
school_applications <- school_applications %>%
  mutate(Category = case_when(
  Ethnicity %in% c("African-American/Black", "American Indian", "Asian", "Hispanic") ~ "Teacher of Color",
  Ethnicity == "White" ~ "White Teacher",
    TRUE ~ "Other"))

school_canidates <- school_canidates %>%
  mutate(Category = case_when(
  Ethnicity %in% c("African-American/Black", "American Indian", "Asian", "Hispanic") ~ "Teacher of Color",
  Ethnicity == "White" ~ "White Teacher",
    TRUE ~ "Other"))

# Hires by School
school_hired <- school_canidates %>%
  filter(Application.Status =="Hired")
school_hired
# Active Vacancies by School
school_vac <- schools_vacancies %>%
  filter(Status =="Active")

# Active Applications
school_apps_active <- school_applications %>%
filter(Application.Status!= "Position Filled/Closed") %>%
filter(Application.Status!= "Hired") %>%
filter(Application.Status!= "Candidate Hired for Another Position")

# Calculate total number of candidates in pool
Total_cands <- school_canidates %>%
  group_by(ApplicantProfile.ID) %>%
  summarise(
    num_apps_per_cand = n(),                         # Calculate the number of applications
    percentage_of_apps_per_cand = num_apps_per_cand / nrow(school_canidates) * 100  # Calculate the percentage
  )
# Vacancies by School

schools_vac  <- school_vac %>%
group_by(Dept.Name) %>%
  summarise(
    num_vac = n(),                         # Calculate the number of teachers
    percentage_of_apps = num_vac / nrow(school_vac) * 100  # Calculate the percentage of teachers of color
  ) %>%
    arrange(desc(num_vac))

school_vac <- left_join(school_vac, schools_vac, by ="Dept.Name")

# Candidates by School
school_canidates <- merge(school_canidates, Total_cands, by = "ApplicantProfile.ID")

# Calculate total number of candidates in pool
unique_cands <- school_canidates %>%
  group_by(ApplicantProfile.ID) %>%
  summarise(
    num_apps_per_cand = n(),                         # Calculate the number of applications
    percentage_of_apps_per_cand = num_apps_per_cand / nrow(school_canidates) * 100  # Calculate the percentage
  )

# Candidates by School
school_canidates <- merge(school_canidates, unique_cands, by = "ApplicantProfile.ID")

# Create unique points to plot candidates
school_canidates$Lat <- jitter(school_canidates$Lat, factor = 0.00001)
school_canidates$Long <- jitter(school_canidates$Long, factor = 0.00001)

school_hired$Lat <- jitter(school_hired$Lat, factor = 0.00001)
school_hired$Long <- jitter(school_hired$Long, factor = 0.00001)

school_cands_hired_sum <-school_hired %>%
  group_by(Dept.ID) %>%
  summarise(
    num_teachers_hired = n(),                         # Calculate the number of teachers
    percentage_of_teachers_hired = num_teachers_hired / nrow(school_hired) * 100  # Calculate the percentage of teachers of color
  ) %>%
  arrange(desc(num_teachers_hired))

school_hired <- left_join(school_hired,school_cands_hired_sum, by = "Dept.ID")

# Create shared Data Frames
Applications_sd <-SharedData$new(school_applications, group = "Applications")
Canidates_sd <-SharedData$new(school_canidates, group = "Canidates")
Hires_sd <-SharedData$new(school_hired, group = "Hires")
Vacancies_sd <- SharedData$new(school_vac, group = "Vacancies")

#Total
Total_Apps <- nrow(Applications_sd$data())
Total_Cands <- nrow(Canidates_sd$data())
Total_Hired <-nrow(Hires_sd$data())
Total_Vac <-nrow(Vacancies_sd$data())
Total_Active_Apps <- nrow(school_apps_active)

TOC_apps <- Applications_sd$data() %>%
  filter(Category == "Teacher of Color")
White_apps <- Applications_sd$data() %>%
  filter(Category == "White Teacher")
TOC_cands <- Canidates_sd$data() %>%
  filter(Category == "Teacher of Color")
White_cands <- Canidates_sd$data() %>%
  filter(Category == "White Teacher")
TOC_hires <- Hires_sd$data() %>%
  filter(Category == "Teacher of Color")
White_hires <- Hires_sd$data() %>%
  filter(Category == "White Teacher")

Total_TOC_apps <- nrow(TOC_apps)
Total_TOC_cands <- nrow(TOC_cands)
Total_TOC_hires <- nrow(TOC_hires)

unique_TOC_values <- unique(TOC_apps$ApplicantProfile.ID)
unique_TOC_values_num <- length(unique_TOC_values)

unique_Total_Cands <-unique(school_canidates$ApplicantProfile.ID)
unique_Total_Cands_num <- length(unique_Total_Cands)

## Schools Doing the Best
# Calculate the percentages
school_hired$Number_Teachers_of_Color <- (school_hired$Black.Teachers + school_hired$Asian.Teachers + school_hired$Hispanic.Teachers)
school_hired$Percent_Teachers_of_Color <- (school_hired$Black.Teachers + school_hired$Asian.Teachers + school_hired$Hispanic.Teachers) / school_hired$Total.Teachers * 100
school_hired$Percent_White <- school_hired$White.Teachers / school_hired$Total.Teachers * 100

schools$Number_Teachers_of_Color <- (schools$Black.Teachers + schools$Asian.Teachers + schools$Hispanic.Teachers)
schools$Percent_Teachers_of_Color <- (schools$Black.Teachers + schools$Asian.Teachers + schools$Hispanic.Teachers) / schools$Total.Teachers * 100
schools$Percent_White <- schools$White.Teachers / schools$Total.Teachers * 100

#Calculate school hiring data
school_coc_hired <- school_hired %>%
  filter(Ethnicity != "White") %>%
  filter(Ethnicity!= "Decline to Identify")

school_white_hired <- school_hired %>%
  filter(Ethnicity == "White")

school_toc_hired_sum <-school_coc_hired %>%
  group_by(Dept.ID) %>%
  summarise(
    num_toc_teachers = n(),                         # Calculate the number of teachers
    percentage_toc_hired = num_toc_teachers / nrow(school_coc_hired) * 100  # Calculate the percentage of teachers of color
  ) %>%
  arrange(desc(num_toc_teachers))

school_cands_hired_sum <-school_hired %>%
  group_by(Dept.ID) %>%
  summarise(
    num_teachers_hired = n(),                         # Calculate the number of teachers
    percentage_of_teachers_hired = num_teachers_hired / nrow(school_hired) * 100  # Calculate the percentage of teachers of color
  ) %>%
  arrange(desc(num_teachers_hired))

school_white_hired_sum <-school_white_hired %>%
  group_by(Dept.ID) %>%
  summarise(
    num_white_teachers_hired = n(),                         # Calculate the number of teachers
    percentage_of_white_teachers_hired = num_white_teachers_hired / nrow(school_white_hired) * 100  # Calculate the percentage of teachers of color
  ) %>%
  arrange(desc(num_white_teachers_hired))

#join school hiring data to school demographic data

best_schools <- left_join(schools,school_cands_hired_sum, by = "Dept.ID")
best_schools <- left_join(best_schools,school_toc_hired_sum, by = "Dept.ID")
best_schools <- left_join(best_schools,school_white_hired_sum, by = "Dept.ID")

# Calculate the number of teachers of color added for each school
best_schools$Added_Diversity <- (best_schools$Number_Teachers_of_Color + best_schools$num_toc_teachers )
# Calculate the percent of teachers of color added for each school
best_schools$Added_Percent_toc <- best_schools$Added_Diversity/best_schools$Total.Teachers * 100
# Calculate the change in percent for hired teachers of color by school 
best_schools$toc_percent_change <- best_schools$Added_Percent_toc - best_schools$Percent_Teachers_of_Color

best_schools%>%
  arrange(desc(toc_percent_change))

best_schools_top10 <- best_schools %>% 
  arrange(desc(toc_percent_change)) %>%
  head(10)

best_schools_top10_num <- sum(best_schools_top10$num_toc_teachers)
rec_schools <- left_join(best_schools,schools_vac, by ="Dept.Name")

rec_schools%>%
  arrange(desc(num_vac)) %>%
  head(10)

rec_schools$potiental_toc <- (rec_schools$num_vac + rec_schools$Added_Diversity)

rec_schools%>%
  arrange(desc(num_vac))

rec_schools$potiental_added_percent_toc <- rec_schools$potiental_toc/best_schools$Total.Teachers * 100

rec_schools%>%
  arrange(desc(num_vac))

rec_schools$potiental_toc_percent_change <- rec_schools$potiental_added_percent_toc - rec_schools$Added_Percent_toc

rec_schoolstop10 <-rec_schools %>%
  arrange(desc(potiental_toc_percent_change)) %>%
  head(10)
rec_schoolstop10_num <- sum (rec_schoolstop10$potiental_toc)

Needs_Improvement <- rec_schools %>%
  filter(percentage_toc_hired < 3.0) %>%
  head(10)

Needs_Impro_num <- sum(Needs_Improvement$num_toc_teachers)

# Create Function for Sunburst
as.sunburstDF <- function(DF, value_column = NULL, add_root = FALSE){
  require(data.table)
  
  colNamesDF <- names(DF)
  
  if(is.data.table(DF)){
    DT <- copy(DF)
  } else {
    DT <- data.table(DF, stringsAsFactors = FALSE)
  }
  
  if(add_root){
    DT[, root := "Total"]  
  }
  
  colNamesDT <- names(DT)
  hierarchy_columns <- setdiff(colNamesDT, value_column)
  DT[, (hierarchy_columns) := lapply(.SD, as.factor), .SDcols = hierarchy_columns]
  
  if(is.null(value_column) && add_root){
    setcolorder(DT, c("root", colNamesDF))
  } else if(!is.null(value_column) && !add_root) {
    setnames(DT, value_column, "values", skip_absent=TRUE)
    setcolorder(DT, c(setdiff(colNamesDF, value_column), "values"))
  } else if(!is.null(value_column) && add_root) {
    setnames(DT, value_column, "values", skip_absent=TRUE)
    setcolorder(DT, c("root", setdiff(colNamesDF, value_column), "values"))
  }
  
  hierarchyList <- list()
  
  for(i in seq_along(hierarchy_columns)){
    current_columns <- colNamesDT[1:i]
    if(is.null(value_column)){
      currentDT <- unique(DT[, ..current_columns][, values := .N, by = current_columns], by = current_columns)
    } else {
      currentDT <- DT[, lapply(.SD, sum, na.rm = TRUE), by=current_columns, .SDcols = "values"]
    }
    setnames(currentDT, length(current_columns), "labels")
    hierarchyList[[i]] <- currentDT
  }
  
  hierarchyDT <- rbindlist(hierarchyList, use.names = TRUE, fill = TRUE)
  
  parent_columns <- setdiff(names(hierarchyDT), c("labels", "values", value_column))
  hierarchyDT[, parents := apply(.SD, 1, function(x){fifelse(all(is.na(x)), yes = NA_character_, no = paste(x[!is.na(x)], sep = ":", collapse = " - "))}), .SDcols = parent_columns]
  hierarchyDT[, ids := apply(.SD, 1, function(x){paste(x[!is.na(x)], collapse = " - ")}), .SDcols = c("parents", "labels")]
  hierarchyDT[, c(parent_columns) := NULL]
  return(hierarchyDT)
}

school_vac_sun <- school_vac %>%
  select(Autonomy.Status, Dept.Name, num_vac)

sunburstDF_vac <- as.sunburstDF(school_vac_sun, value_column = "num_vac", add_root = TRUE)

school_app_sun <- school_canidates %>%
  select(Applicant.Type, Ethnicity, num_apps_per_cand.x)

sunburstDF_app <- as.sunburstDF(school_app_sun, value_column = "num_apps_per_cand.x", add_root = TRUE)

school_coc_hired_sun <- school_coc_hired %>%
  select(Applicant.Type, Ethnicity, num_teachers_hired)

sunburstDF_school_coc_hired <- as.sunburstDF(school_coc_hired_sun, value_column = "num_teachers_hired", add_root = TRUE)

school_TOC_cands_sun <- TOC_cands %>%
  select(Applicant.Type, Ethnicity, num_apps_per_cand.x)

sunburstDF_TOC_cands_sun <- as.sunburstDF(school_TOC_cands_sun, value_column = "num_apps_per_cand.x", add_root = TRUE)

best_schools_top10_sun <- best_schools_top10 %>% 
  select(Autonomy.Status, Dept.Name, num_toc_teachers)

sunburstDF_best_schools_top10_sun <- as.sunburstDF(best_schools_top10_sun, value_column = "num_toc_teachers", add_root = TRUE)

Needs_Improvement_schools_top10_sun <- Needs_Improvement %>% 
  select(Autonomy.Status, Dept.Name, num_toc_teachers)

sunburstDF_Needs_Improvement_schools_top10_sun <- as.sunburstDF(Needs_Improvement_schools_top10_sun, value_column = "num_toc_teachers", add_root = TRUE)

rec_schools_top10_sun <- rec_schoolstop10 %>% 
  select(Autonomy.Status, Dept.Name, potiental_toc)

sunburstDF_rec_schools_top10_sun <- as.sunburstDF(rec_schools_top10_sun, value_column = "potiental_toc", add_root = TRUE)
```

Background
=====================================

Column {data-width=650 }
-----------------------------------------------------------------------
**Data Pools**

### Active School Vacancies
```{r}
school_vac_num <- nrow(school_vac)
valueBox(school_vac_num, icon = "fa-school")
```

### Active Applicants
```{r}
valueBox(Total_Active_Apps, icon = "fa-file-circle-check")
```

### Candidates of Color
```{r}
gauge(round(100*(unique_TOC_values_num/unique_Total_Cands_num)), min = 0, max = 100, symbol = '%', 
  label = "Candidates of Color", gaugeSectors(success = c(60, 100), warning = c(31, 59), danger = c(0, 30)))
```


Column {data-width=650 }
-----------------------------------------------------------------------
**Hiring Data **

### Teachers Hired to date
```{r}
school_hired_num <- nrow(school_hired) 
  valueBox(school_hired_num, icon = "fa-chalkboard-user")
```

### Teachers of Color Hired to date
```{r}
school_TOC_hires_num <- nrow(TOC_hires) 
valueBox(school_TOC_hires_num, icon = "fa-users-line")
```

### Teachers of Color Hired
```{r}
gauge(round(100*(Total_TOC_hires/Total_Hired)), min = 0, max = 100, symbol = '%', 
  label = "Candidates of Color", gaugeSectors(success = c(60, 100), warning = c(31, 59), danger = c(0, 30)))
```


Row {data-width=650 }
-----------------------------------------------------------------------
**Recommendations**

### Teachers of Color Hired at Top Schools

```{r}
valueBox(best_schools_top10_num, icon = "fa-thumbs-up")
```

### Teachers of Color Hired at Needs Improvement Schools
```{r}
valueBox(Needs_Impro_num, icon = "fa-thumbs-down")
```

### Potential Teachers of Color
```{r}
gauge(round(100*(rec_schoolstop10_num/Total_Hired)), min = 0, max = 100, symbol = '%', 
  label = "% Teacher of Color", gaugeSectors(success = c(59, 100), warning = c(31, 58), danger = c(0, 30)))
```


Vacancies Pool
=====================================

Inputs {.sidebar data-width=200}
-----------------------------------------------------------------------
### Vacancies Filters

```{r vaca school filter}
filter_select("Dept.Name", "Select School", Vacancies_sd, ~Dept.Name)
```

```{r vaca job filter}
filter_select("Posting.ID", "Select Job Posting", Vacancies_sd, ~Posting.ID)
```

```{r vaca autonomy filter}
filter_select("Autonomy.Status", "Select Autonomy Status", Vacancies_sd, ~Autonomy.Status)
```

Column {data-width=650 .tabset .tabset-fade .colored}
-----------------------------------------------------------------------
### School Vacancies

```{r}
plot_ly(data = sunburstDF_vac, ids = ~ids, labels= ~labels, parents = ~parents, values= ~values, type='sunburst', branchvalues = 'total')
```

### Map

```{r vaca data}

color_palette <- colorFactor(
  palette = c("blue", "green", "orange", "black", "purple", "brown", "white"),
  domain = Vacancies_sd$Autonomy.Status
)


leaflet() %>%
  setView(lng = -71.0589, lat = 42.3601, zoom = 12) %>%
  addProviderTiles("CartoDB.DarkMatter", group = "Dark") %>%
  addProviderTiles("Esri.WorldGrayCanvas", group = "Grey") %>%
    addCircleMarkers(
    data = Vacancies_sd,
    lng = ~Long,
    lat = ~Lat,
    color = ~color_palette(Autonomy.Status),
    radius = 6,
    fillOpacity = 0.8,
    popup = ~Dept.Name,
    clusterOptions = markerClusterOptions(),
    group = "Vacancies") %>%
    addLayersControl(overlayGroups = c("Vacancies"), 
                     baseGroups = c("Dark","Grey"), 
                     options = layersControlOptions(collapsed = FALSE)) %>%
    addLegend("bottomleft", 
              pal = color_palette, 
              values = Vacancies_sd$data()$Autonomy.Status,
              title = "Ethnicity",
              opacity = 1)
```

Row {data-width=350 .tabset .tabset-fade .colored}
-----------------------------------------------------------------------

### School
```{r vaca school pie}
plot_ly(Vacancies_sd,
        labels = ~Dept.Name,
        values = ~num_vac, 
        type = 'pie',
        marker = list(colors = c('#bcbd22', '#2ca02c')),
        textposition = 'inside',
        textinfo = 'label',
        showlegend=T) %>%
  layout(title = "School Vacancies", legend = list(orientation ="h",  xanchor = "center", x = 0.5, y = -0.1))

```


### Autonomy Status
```{r vaca type pie}
plot_ly(Vacancies_sd,
        labels = ~ Autonomy.Status,
        values = ~num_vac, 
        type = 'pie',
        marker = list(colors = c('#bcbd22', '#2ca02c')),
        textposition = 'inside',
        textinfo = 'label',
        showlegend=T) %>%
  layout(title = "School Vacancies", legend = list(orientation ="h",  xanchor = "center", x = 0.5, y = -0.1))
```

Applicant Pool
=====================================

Inputs {.sidebar data-width=200}
-----------------------------------------------------------------------

### Applications Filters

```{r app school filter}
filter_select("Dept.Name", "Select School", Applications_sd, ~Dept.Name)
```

```{r app ethnicity filter}
filter_select("Ethnicity", "Select Ethnicity", Applications_sd, ~Ethnicity)
```

```{r app status filter}
filter_select("Status", "Select Application Status", Applications_sd, ~Status)
```

```{r app Type filter}
filter_select("Applicant.Type", "Select Type", Applications_sd, ~Applicant.Type)
```

```{r app candidate filter}
filter_select("ApplicantProfile.ID", "Select Canidate", Applications_sd, ~ApplicantProfile.ID)
```

```{r app job filter}
filter_select("Posting.ID", "Select Job Posting", Applications_sd, ~Posting.ID)
```

```{r app autonomy filter}
filter_select("Autonomy.Status", "Select Autonomy Status", Applications_sd, ~Autonomy.Status)
```

Column {data-width=650 .tabset .tabset-fade .colored}
-----------------------------------------------------------------------

### Application Type

```{r}
plot_ly(data = sunburstDF_app, ids = ~ids, labels= ~labels, parents = ~parents, values= ~values, type='sunburst', branchvalues = 'total')
```

### Data Table
```{r app data}
datatable(Applications_sd, extensions="Scroller", style="bootstrap", class="compact", width="100%",
            options=list(deferRender=TRUE, scrollY=300, scroller=TRUE))
```

Row {data-width=350 .tabset .tabset-fade .colored}
-----------------------------------------------------------------------

### Category
```{r app category pie}
plot_ly(Applications_sd,
        labels = ~Category,
        values = ~Total_Apps, 
        type = 'pie',
        marker = list(colors = c('#bcbd22', '#2ca02c')),
        textposition = 'inside',
        textinfo = 'label+percent',
        showlegend=T) %>%
  layout(title = "Application Breakdown", legend = list(orientation ="h",  xanchor = "center", x = 0.5, y = -0.1))
```

### Ethnicity
```{r app ethnicity pie}
plot_ly(Applications_sd,
        labels = ~Ethnicity,
        values = ~Total_Apps, 
        type = 'pie',
        marker = list(colors = c('#bcbd22', '#2ca02c')),
        textposition = 'inside',
        textinfo = 'label+percent',
        showlegend=T) %>%
  layout(title = "Application Breakdown", legend = list(orientation ="h",  xanchor = "center", x = 0.5, y = -0.1))
```

### Type
```{r app type pie}
plot_ly(Applications_sd,
        labels = ~Applicant.Type,
        values = ~Total_Apps, 
        type = 'pie',
        marker = list(colors = c('#bcbd22', '#2ca02c')),
        textposition = 'inside',
        textinfo = 'label+percent',
        showlegend=T) %>%
  layout(title = "Application Breakdown", legend = list(orientation ="h",  xanchor = "center", x = 0.5, y = -0.1))
```

### Schools
```{r app school pie}
plot_ly(Applications_sd,
        labels = ~Dept.Name,
        values = ~Total_Apps, 
        type = 'pie',
        marker = list(colors = c('#bcbd22', '#2ca02c')),
        textposition = 'inside',
        textinfo = 'label+percent',
        showlegend=T) %>%
  layout(title = "Application Breakdown", legend = list(orientation ="h",  xanchor = "center", x = 0.5, y = -0.1))
```

### Autonomy Status
```{r app autonomy pie}
plot_ly(Applications_sd,
        labels = ~Autonomy.Status,
        values = ~Total_Apps, 
        type = 'pie',
        marker = list(colors = c('#bcbd22', '#2ca02c')),
        textposition = 'inside',
        textinfo = 'label+percent',
        showlegend=T) %>%
  layout(title = "Application Breakdown", legend = list(orientation ="h",  xanchor = "center", x = 0.5, y = -0.1))
```

###

Candidate Pool
=====================================

Inputs {.sidebar data-width=200}
-----------------------------------------------------------------------

### Canidate Filters

```{r can school filter}
filter_select("Dept.Name", "Select School", Canidates_sd, ~Dept.Name)
```

```{r can ethnicity filter}
filter_select("Ethnicity", "Select Ethnicity", Canidates_sd, ~Ethnicity)
```

```{r can status filter}
filter_select("Status", "Select Application Status", Canidates_sd, ~Status)
```

```{r can candidate filter}
filter_select("ApplicantProfile.ID", "Select Canidate", Canidates_sd, ~ApplicantProfile.ID)
```

```{r can job filter}
filter_select("Posting.ID", "Select Job Posting", Canidates_sd, ~Posting.ID)
```

```{r can autonomy filter}
filter_select("Autonomy.Status", "Select Autonomy Status", Canidates_sd, ~Autonomy.Status)
```

```{r can transformation filter}
filter_checkbox("Transformation.School", "Select Transformation", Canidates_sd, ~Transformation.School, allLevels = TRUE)
```

```{r can turnaround filter}
filter_checkbox("Turnaround.School", "Select Turnaround", Canidates_sd, ~Turnaround.School, allLevels = TRUE)
```

Column {data-width=650 .tabset .tabset-fade .colored}
-----------------------------------------------------------------------

### Candidates of Color

```{r}
plot_ly(data = sunburstDF_TOC_cands_sun, ids = ~ids, labels= ~labels, parents = ~parents, values= ~values, type='sunburst', branchvalues = 'total')
```


### Map 
```{r can map}

color_palette <- colorFactor(
  palette = c("blue", "green", "orange", "black", "purple", "brown", "white"),
  domain = Canidates_sd$Ethnicity
)


leaflet() %>%
  setView(lng = -71.0589, lat = 42.3601, zoom = 12) %>%
  addProviderTiles("CartoDB.DarkMatter", group = "Dark") %>%
  addProviderTiles("Esri.WorldGrayCanvas", group = "Grey") %>%
    addCircleMarkers(
    data = Canidates_sd,
    lng = ~Long,
    lat = ~Lat,
    color = ~color_palette(Ethnicity),
    radius = 6,
    fillOpacity = 0.8,
    popup = ~Dept.Name,
    clusterOptions = markerClusterOptions(),
    group = "Applications") %>%
    addCircleMarkers(data = Canidates_sd,
                    lng = ~Long,
                    lat = ~Lat,
                    color = ~color_palette(Ethnicity),
                    popup = ~Dept.Name,
                    fillOpacity = ifelse(test = Canidates_sd$data()$Ethnicity != "White", yes = 1, no = 0),
                    fillColor = "red",
                    group = "Canidates") %>%
    addLayersControl(overlayGroups = c("Applications","Canidates"), 
                     baseGroups = c("Dark","Grey"), 
                     options = layersControlOptions(collapsed = FALSE)) %>%
    addLegend("bottomleft", 
              pal = color_palette, 
              values = Canidates_sd$data()$Ethnicity,
              title = "Ethnicity",
              opacity = 1)
```

### Data Table

```{r can data}

datatable(Canidates_sd, extensions="Scroller", style="bootstrap", class="compact", width="100%",
            options=list(deferRender=TRUE, scrollY=300, scroller=TRUE))

```

Hire
=====================================

Inputs {.sidebar data-width=200}
-----------------------------------------------------------------------
### Hire Filters
```{r hires school filter}
filter_select("Dept.Name", "Select School", Hires_sd, ~Dept.Name)
```

```{r hires ethnicity filter}
filter_select("Ethnicity", "Select Ethnicity", Hires_sd, ~Ethnicity)
```

```{r hires candidate filter}
filter_select("ApplicantProfile.ID", "Select Canidate", Hires_sd, ~ApplicantProfile.ID)
```

```{r hires job filter}
filter_select("Posting.ID", "Select Job Posting", Hires_sd, ~Posting.ID)
```

```{r hires autonomy filter}
filter_select("Autonomy.Status", "Select Autonomy Status", Hires_sd, ~Autonomy.Status)
```

```{r hires transformation filter}
filter_checkbox("Transformation.School", "Select Transformation", Hires_sd, ~Transformation.School, allLevels = TRUE)
```

```{r hires turnaround filter}
filter_checkbox("Turnaround.School", "Select Turnaround", Hires_sd, ~Turnaround.School, allLevels = TRUE)
```

Column {data-width=650 .tabset .tabset-fade .colored}
-----------------------------------------------------------------------

### Teacher of Color Hires

```{r}
plot_ly(data = sunburstDF_school_coc_hired, ids = ~ids, labels= ~labels, parents = ~parents, values= ~values, type='sunburst', branchvalues = 'total')
```


### Hires Map 
```{r hires map}
color_palette <- colorFactor(
  palette = c("blue", "green", "orange", "black", "purple", "brown", "white"),
  domain = Canidates_sd$Ethnicity
)


leaflet() %>%
  setView(lng = -71.0589, lat = 42.3601, zoom = 12) %>%
  addProviderTiles("CartoDB.DarkMatter", group = "Dark") %>%
  addProviderTiles("Esri.WorldGrayCanvas", group = "Grey") %>%
  addCircleMarkers(data = Hires_sd,
                    lng = ~Long,
                    lat = ~Lat,
                    color = ~color_palette(Ethnicity),
                    popup = ~Dept.Name,
                    fillOpacity = ifelse(test = Hires_sd$data()$Ethnicity != "White", yes = 1, no = 0),
                    fillColor = "red",
                    group = "Hires") %>%
    addLayersControl(overlayGroups = c("Hires"), 
                     baseGroups = c("Dark","Grey"), 
                     options = layersControlOptions(collapsed = FALSE)) %>%
    addLegend("bottomleft", 
              pal = color_palette, 
              values = Hires_sd$data()$Ethnicity,
              title = "Ethnicity",
              opacity = 1)
```

### Data Table
```{r}
datatable(Hires_sd, extensions="Scroller", style="bootstrap", class="compact", width="100%",
            options=list(deferRender=TRUE, scrollY=300, scroller=TRUE))
```

Row {data-width=350 .tabset .tabset-fade .colored}
-----------------------------------------------------------------------

### Category
```{r hires category pie}
plot_ly(Hires_sd,
        labels = ~Category,
        values = ~num_teachers_hired, 
        type = 'pie',
        marker = list(colors = c('#bcbd22', '#2ca02c')),
        textposition = 'inside',
        textinfo = 'label+percent',
        showlegend=T) %>%
  layout(title = "Teacher Hire Breakdown", legend = list(orientation ="h",  xanchor = "center", x = 0.5, y = -0.1))
```

### Ethnicity
```{r hires ethnicity pie}
plot_ly(Hires_sd,
        labels = ~Ethnicity,
        values = ~num_teachers_hired, 
        type = 'pie',
        marker = list(colors = c('#bcbd22', '#2ca02c')),
        textposition = 'inside',
        textinfo = 'label+percent',
        showlegend=T) %>%
  layout(title = "Hires by Ethnicity", legend = list(orientation ="h",  xanchor = "center", x = 0.5, y = -0.1))
```

### Type
```{r hires type pie}
plot_ly(Hires_sd,
        labels = ~Applicant.Type,
        values = ~num_teachers_hired, 
        type = 'pie',
        marker = list(colors = c('#bcbd22', '#2ca02c')),
        textposition = 'inside',
        textinfo = 'label+percent',
        showlegend=T) %>%
  layout(title = "Hires By Applicate Type", legend = list(orientation ="h",  xanchor = "center", x = 0.5, y = -0.1))
```

### Schools
```{r hires school pie}
plot_ly(Hires_sd,
        labels = ~Dept.Name,
        values = ~num_teachers_hired, 
        type = 'pie',
        marker = list(colors = c('#bcbd22', '#2ca02c')),
        textposition = 'inside',
        textinfo = 'label+percent',
        showlegend=T) %>%
  layout(title = "Teachers Hired by School", legend = list(orientation ="h",  xanchor = "center", x = 0.5, y = -0.1))
```

### Autonomy Status
```{r hires autonomy pie}
plot_ly(Hires_sd,
        labels = ~Autonomy.Status,
        values = ~num_teachers_hired, 
        type = 'pie',
        marker = list(colors = c('#bcbd22', '#2ca02c')),
        textposition = 'inside',
        textinfo = 'label+percent',
        showlegend=T) %>%
  layout(title = "Hires by Autonomy Status", legend = list(orientation ="h",  xanchor = "center", x = 0.5, y = -0.1))
```

School Performance
=====================================

Row {data-width=350}
-----------------------------------------------------------------------
### Top Performers
**Schools with the highest number of Teacher of Color Hires**
```{r}
plot_ly(data = sunburstDF_best_schools_top10_sun, ids = ~ids, labels= ~labels, parents = ~parents, values= ~values, type='sunburst', branchvalues = 'total')
```


Row {data-width=350}
-----------------------------------------------------------------------
### Needs Improvement 
**Schools with the lowest number of Teacher of Color Hires**
```{r}
plot_ly(data = sunburstDF_Needs_Improvement_schools_top10_sun, ids = ~ids, labels= ~labels, parents = ~parents, values= ~values, type='sunburst', branchvalues = 'total')
```

Recommendations 
=====================================

### Teacher of Color Hires
**Potential number of teachers of color**
```{r}
plot_ly(data = sunburstDF_rec_schools_top10_sun, ids = ~ids, labels= ~labels, parents = ~parents, values= ~values, type='sunburst', branchvalues = 'total')

```