Data provided by the New York State Office of Mental Health and found publicly on DATA.NY.GOV
Example created by Meghan Harris with the flexdashboard, Crosstalk, SummaryWidget, and DT packages.
---
title: "New York State's (Brooklyn,NY) Local Mental Health Programs"
output:
flexdashboard::flex_dashboard:
vertical_layout: fill
source_code: embed
css: scripts/nycmhstyle.css
---
```{r setup, include=FALSE}
#Library load in.#
library(flexdashboard)
library(knitr)
library(tidyverse)
library(leaflet)
library(leafem)
library(crosstalk)
library(DT)
library(summarywidget)
library(raster)
#Loading the datasets into the environment.#
#MH programs with geocodes#
MHprograms <- readRDS("data/mhprogramsnyc.RDS")
#Converting data frames into shared data objects with crosstalk. This will allow the map, filters, and tables to be interactive and dynamic.#
Sharedgeodata <- SharedData$new(MHprograms)
```
Column {data-width=550}
-----------------------------------------------------------------------
###
```{r map}
#Pulling a "Home" icon I've hosted on the internet===
Homeimg <- htmltools::HTML(paste(""))
#Naming the home image for the addhomebutton function in the leaflet map===
Home <- list("Home" = Homeimg)
#Generating a bounding box of the entire data set. This will act as our "homebase" to zoom back to when the home button is clicked on===
homebase <- ggmap::make_bbox(lon, lat, data = MHprograms)
# Retrieving the center point for the map data to set the "home" view===
coordinates(MHprograms) <- ~lon+lat
proj4string(MHprograms) <- "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"
mapcenter <- coordinates(as(extent(MHprograms), "SpatialPolygons"))
#Creating the leaflet map from the shared geo data object===
Sharedgeodata %>%
leaflet() %>%
addProviderTiles(providers$OpenStreetMap) %>%
addAwesomeMarkers(
popup = ~paste0(
"",MHprograms$`Agency Name`, "
",
"",MHprograms$`Program Name`,"
",
"Phone: ",MHprograms$`Agency Phone`, "
",
MHprograms$`Program Address 1`, "
",
MHprograms$City, MHprograms$`Program State`, MHprograms$`Program Zip`),
icon = awesomeIcons(
library = "fa",
icon = ifelse(
test = MHprograms$`Program Category Description` == "Outpatient",
yes = "fa-stethoscope",
no = ifelse(
test = MHprograms$`Program Category Description` == "Inpatient",
yes = "fa-bed",
no = ifelse(
test = MHprograms$`Program Category Description` == "Emergency",
yes = "fa-ambulance",
no = "fa-users"
))),
iconColor = "#ffffff",
markerColor = "darkpurple")) %>%
addHomeButton(ext = homebase,
group = Home,
position = "topright") %>%
setView(lng = mapcenter[1] , lat = mapcenter[2], zoom = 12)
```
Column {data-width=450}
-----------------------------------------------------------------------
### **Total Locations Found:** {data-height=70}
`r summarywidget(Sharedgeodata, statistic='count', digits=0)`
### **Program Information:** {data-height=200}
```{r datatable}
Sharedgeodata %>%
DT::datatable(
rownames = FALSE,
style = "bootstrap",
class = "compact",
selection = "multiple",
options = list(
dom = "tip",
columnDefs = list(
list(width = '50%',
visible = FALSE,
targets = c(0,4:13,15:16))),
colnames = c(
"Location Name" = "Program Name",
"Ages Served" = "Populations Served",
"Phone Number" = "Program Phone",
"Address" = "Complete Address"
)))
```
### **Map Filters:**
```{r mapfilters}
filter_checkbox(
id = "Program Category Description",
label = "Program Type",
sharedData = Sharedgeodata,
group = ~`Program Category Description`,
inline = TRUE
)
```
```{r mapfilters2}
filter_select(
id = "Program Subcategory Description",
label = "Program Setting",
sharedData = Sharedgeodata,
group = ~`Program Subcategory Description`,
multiple = TRUE
)
```
```{r mapfilters3}
filter_select(
id = "Populations Served",
label = "Ages Served",
sharedData = Sharedgeodata,
group = ~`Populations Served`,
multiple = FALSE
)
```
Data provided by the New York State Office of Mental Health and found publicly on DATA.NY.GOV
Example created by Meghan Harris with the flexdashboard, Crosstalk, SummaryWidget, and DT packages.