About

Row

About this Interactive Web Visualization Tool

Row

HAT Datasets

HAT Data of 9 HAT-only-Managed-Sites
1. HAT Restoration Crew Site Data
* Metrics: daily crew hours, daily invasive species removed (cubic metres); yearly crew hours, yearly invasive species removed (cubic metres)
* Sites: Bear Hill, Calypso Woods, Camas Hill, Funk, Havenwood, Matson, Oak Haven, Purple Sanicle, Yates,
* Datasets: Restoration Crew Data.xlsx: Apr 2022-Sep 2025; Sites Daily; Sites Yearly; Top Invasives Site

2. Matson Mattocks Field Logs
* Metrics: daily volunteer work hours, daily volunteer invasive species removal
* Sites: added to Matson Work Crew data
* Datasets: Matson Mattocks Field Logs: Apr 2022-Sep 2025; Sites Daily; Top Invasives Site

3. Cover Data 2024-2025
* Metrics: cover, species
* Sites: Matson, Oak Haven
* Datasets: Cover Data 2024-2025: Cover Mean % (Native/Invasive & Treated/Untreated); Species Richness

4. Site Data
* Metrics: Map Location; Apr 2022-Sep 2025; Top 5 invasives, Hours per m3 Biomass, staff hours, biomass removed
* Sites: Havenwood, Matson, Oak Haven
* Data: https://hat.bc.ca/community-based-restoration

How to Use This Interactive Tool

How to use this interactive data visualization tool
Top Header Navigation Pages
* Navigation links in the top header host different data visualization charts and datatables
* Each link uses a different dataset and is responsive to different filters

Filters
* All years and sites are shown until data is filtered
* Filters must be cleared, using delete or backspace key in order to start new filter
* Filtered summary statistics accompany each data set

Interactive Visualizations
* Hover over data visualizations to view tooltips
* Data visualization can be zoom-focused by using a 'click-drag' over a certain area
* Double-click within chart to return to original version
* If all else fails, refresh webpage in browser

Tips for Analyzing Chart Visualizations

What Story Is Being Told By The Data Visualizations
Notice any Patterns Trends?
* Over Years
* Between Species
* Same Site

If Hours and Biomass trend down, is it worth still sending crew out?
* How important is regular maintenance of removing Invasives?
* Is there a threshold of amount of biomass removed to justify Crew Hours?

ER390 Project Proposal

Background Research
* Comparing monitoring restoration projects using consistent vegetation measurements techniques, may help identify responses to stressors affecting already compromised and rare GOE.
* Visually representing data helps make complex data understandable, reveals patterns, creates 'data-based story-telling', and communicates insights for making effective management decisions.
* RMarkdown-generated reports can help create reproducible research.

Project Goals and Overall Purpose
* To create an interactive data visualization tool for non-coders, based on HAT's needs, with tutorial instructions
* Use open-source R code to format monitoring data collected at multiple HAT sites, to communicate data information and patterns.

Project Objectives
* Analyze and transform collected data
* Write reproducible data visualization code
* Create interactive, browser-based Data Visualization Tool
* Analyze resulting patterns

RStudio-created Project Deliverables
* RMarkdown Data Processing Document Tool using best practises for data
* Interactive Browser-based Data Visualizations Tool with Tutorial for Use
* Written Report: Due 2026-04-15; publish in online RNS Ecorestoration journal
* Project Presentation: By mid-May 2026

Sites Daily

Row

Crew (& Matson Volunteer) Data for hours worked & biomass cleared

Daily crew data was collected for work hours, invasive species, and biomass removed.
Note: Some missing data for fall 2025. Tip: Start by choosing a site..

Row

Hours by Year

Biomass by Year

Area of Biomass by Year

Datatable

Daily Crew Hours (& Volunteer) & Biomass Datatable

Sites Yearly

Row

Crew Data Summarized

Yearly summary of daily data collected for crew hours, invasive species and biomass removed. Hours required per cubic metre of biomass shows labour cost. Note: Some missing data for fall 2025

Row

Crew Hours

Biomass Removed

Area of Biomass Removed

Hours per Biomass

Area per Biomass

Datatable

Yearly Crew Hours (& Volunteer) & Biomass Datatable

Top 5 Invasives Sites

Row

Top 5 Invasive Species Biomass by Site

Multiple facets compare 8 sites for invasive species biomass removed (Bear Hill didn't differentiate any species from 'mixed species', thus doesn't show). Note: Some missing data for fall 2025

Row

Top 5 Invasives by Site

Datatable Daily

Daily Crew Hours (& Volunteer) & Top 5 Species Biomass Datatable

Datatable Yearly

Yearly Crew Hours (& Volunteer) Hours & Top 5 Species Biomass Datatable

Cover Mean

Row

Mean % Species Cover Data

Cover data was collected using quadrat-sampling methods at Matson in July 2024 and 2025, and at Oak Haven, in both treated and untreated sample plots, during April 2024 and 2025. As different seasonal meadows species were sampled, the comparison data between sites may not be as meaningful as if sampled during the same season in different years.

Row

Native Species (bar)

Native Species (points with error)

Invasive Species

Mixed Grasses

Datatable

Mean Cover (Native/Invasive & Treated/Untreated) Datatable

Top 5 Cover

Row

Mean % Top 5 Native Species Cover Data

Mean cover data is subset to view only top 5 Native Species. Error bars show the upper and lower ranges of the standard deviation from mean values.

Row

Top 5 Native Species Site~Year (Error bar)

Datatable

Top 5 Mean Cover (Native/Invasive & Treated/Untreated) Datatable

Species Richness

Row

Species Richness Unique Count @ Matson & Oak Haven

Mean % cover data was collected using quadrat-sampling methods July 2024 and 2025 at Matson, and April 2024 and 2025 at Oak Haven. Species Richness counts each unique species found. When meadows species were sampled during different seasons, any meaningful comparison between sites may be affected. Example Analysis: Invasive species count is higher in treated areas ... Does invasive species removal create an environment for more invasive species to move in?

Row

Species Counts by Year & Site

Datatable

Species Count Datatable

Map

Row

Interactive Map of 3 HAT Managed Public GOE Sites

3 public HAT sites listed on HAT's webpage, all other sites are on private, non-public land with location protected for privacy. Click map markers to open pop-up windows site-specific information.

Row

Interactive Map

Datatable

HAT Public Sites Datatable

R version 4.2.1 (2022-06-23)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Mojave 10.14.6

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRlapack.dylib

locale:
[1] en_CA.UTF-8/en_CA.UTF-8/en_CA.UTF-8/C/en_CA.UTF-8/en_CA.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] leaflet_2.1.1            DT_0.26                  plotly_4.10.1           
 [4] lubridate_1.9.3          forcats_1.0.0            stringr_1.5.2           
 [7] dplyr_1.1.4              purrr_1.0.2              readr_2.1.4             
[10] tidyr_1.3.0              tibble_3.2.1             ggplot2_3.4.0           
[13] tidyverse_2.0.0          summarywidget_0.0.0.9000 crosstalk_1.2.0         
[16] htmltools_0.5.3          flexdashboard_0.6.2     

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.9              leaflet.providers_1.9.0 digest_0.6.30          
 [4] utf8_1.2.2              mime_0.12               R6_2.5.1               
 [7] evaluate_0.17           httr_1.4.4              highr_0.9              
[10] pillar_1.11.1           rlang_1.1.6             lazyeval_0.2.2         
[13] rstudioapi_0.14         data.table_1.14.2       jquerylib_0.1.4        
[16] rmarkdown_2.17          labeling_0.4.2          htmlwidgets_1.5.4      
[19] shiny_1.7.3             compiler_4.2.1          httpuv_1.6.6           
[22] xfun_0.41               pkgconfig_2.0.3         tidyselect_1.2.0       
[25] viridisLite_0.4.1       tzdb_0.3.0              withr_2.5.0            
[28] later_1.3.0             grid_4.2.1              jsonlite_1.8.8         
[31] xtable_1.8-4            gtable_0.3.6            lifecycle_1.0.3        
[34] magrittr_2.0.3          scales_1.4.0            cli_3.6.5              
[37] stringi_1.7.8           cachem_1.0.6            farver_2.1.1           
[40] fs_1.5.2                promises_1.2.0.1        bslib_0.4.0            
[43] ellipsis_0.3.2          generics_0.1.3          vctrs_0.6.5            
[46] RColorBrewer_1.1-3      tools_4.2.1             dichromat_2.0-0.1      
[49] glue_1.6.2              hms_1.1.2               fastmap_1.1.0          
[52] yaml_2.3.5              timechange_0.2.0        memoise_2.0.1          
[55] knitr_1.40              sass_0.4.2             
---
title: "Visualizing HAT Monitoring Data"
output: 
  flexdashboard::flex_dashboard:
    #css: flexbox-style.css
    orientation: rows
    vertical_layout: fill
    theme: 
      version: 4
      bootswatch: flatly
    source_code: embed
---

  <script src="https://cdn.plot.ly/plotly-3.3.0.min.js" charset="utf-8"></script>
  <script src="https://d3js.org/d3.v3.min.js"></script>
  

```{r include=FALSE}
knitr::opts_chunk$set(
	message = FALSE,
	warning = FALSE
)

# HAT Log offline
knitr::include_graphics("images/HAT-logo-ss.png")
```

```{css}
/* Set font color of inactive tab to green */
.nav-tabs-custom .nav-tabs > li > a {
  color: green;
} 

/* Set font color of active tab to purple */
.nav-tabs-custom .nav-tabs > li.active > a {
  color: purple;
} 

/* To set color on hover */
.nav-tabs-custom .nav-tabs > li.active > a:hover {
  color: purple;
}

/* To set tab background colour 
.nav-tabs-custom .nav-tabs  {
  background-color: lightgray;
}
*/
  

.section.sidebar {
  padding-left: 10px;
  margin-left: 5px;
}


/* navbar colour  */
.navbar-inverse {
  background-color: #fd7e14;
  border-color: #1967be;
}

p {
  font-weight: bold;
}

.container {
    display: inline;
    /* padding: 0.2em 0.6em 0.3em; */
    font-size: 70%;
    font-weight: bold;
    line-height: 1;
    color: #b5c0c1;
    background-color: #95a5a6; /* #b5c0c1  or #C7EED4 Light grayish cyan - lime green */
    display: flex;
    flex-wrap: wrap; /* Allows items to move to the next line */
    text-align: center;
    white-space: nowrap;
    vertical-align: baseline;
    border-radius: 0.25em;
}

.value {
  font-size: 95%;
  color: black; /* Change the main value font color */
  background-color: #95a5a6; /* #addacd  Light minty background */
  font-weight: bold;
  width: 220px;
  padding: 5px;
  margin: 5px;
  /* Borders */
  border: 2px solid #000; /* Blue solid border #007bff */
  border-radius: 8px; /* Rounded corners */
  /* Text styling */
  text-align: center;
  font-family: Arial, sans-serif;
  /* Ensures padding border dont affect set width */
  box-sizing: border-box;
}

.caption {
  color: black; /* Change the caption font color */
  font-size: 85%;  
}
```

```{r  include=FALSE, load-libraries}
# Load Libraries
#############################################
# uncomment install.packages("") to install a package, then replace comment #

#############################################
# install.packages("flexdashboard")
library(flexdashboard) # dashboard
# install.packages("htmltools")
library(htmltools) # write HTML code in flexdashboard
# install.packages("crosstalk")
library(crosstalk) # shared data filters
# devtools::install_github("kent37/summarywidget")
library(summarywidget) # filtered data summary

# install.packages("tidyverse")
library(tidyverse) # includes ggplot2
# install.packages("plotly")
library(plotly) # interactive plots > ggplot2 requires plotly wrap for crosstalk
# install.packages("DT")
library(DT) # tables
# install.packages("leaflet")
library(leaflet) # interactive map
```


```{r data-download, include = FALSE}
# Load Data
################################# 
# Sites Data
HAT_sites_HAT <- read.csv("data/HAT-Sites-HAT.csv", fileEncoding="UTF-8")
str(HAT_sites_HAT)
head(HAT_sites_HAT)

################################# 
crew_data_sep_sub_1 <- read.csv("data/crew_data_sep_sub.csv", fileEncoding="UTF-8")

# Crew Data
crew_data_sep_sub_1 <- crew_data_sep_sub_1 %>% rename(Site = Work_Site)

crew_data_sep_sub_1$Site <- gsub("Matson Conservation Area", "Matson", crew_data_sep_sub_1$Site)
crew_data_sep_sub_1$Site <- gsub("Oak Haven Park", "Oak Haven", crew_data_sep_sub_1$Site)
crew_data_sep_sub_1$Site <- gsub("Havenwood Park", "Havenwood", crew_data_sep_sub_1$Site)
colnames(crew_data_sep_sub_1)

# Date format
str(crew_data_sep_sub_1)
crew_data_sep_sub_1$Date <- as.Date(crew_data_sep_sub_1$Date)

str(crew_data_sep_sub_1)
# remove 3 rows with NA
# Matson 2025-10-21
# Matson 2024-11-14
# Camas Hill 2025-09-04

crew_data_sep_sub_1_filtered <- crew_data_sep_sub_1 %>%
  filter(Date != "2025-10-21")
crew_data_sep_sub_1_filtered <- crew_data_sep_sub_1 %>%
  filter(Date != "2024-11-14")
crew_data_sep_sub_1_filtered <- crew_data_sep_sub_1 %>%
  filter(Date != "2025-09-04")

# Crew Data
crew_data_sep_sub_sum_by_group_site_1 <- read.csv("data/crew_data_sep_sub_sum_by_group_site_hr_bio_ratio.csv", fileEncoding="UTF-8")
str(crew_data_sep_sub_sum_by_group_site_1)
head(crew_data_sep_sub_sum_by_group_site_1)

crew_data_sep_sub_sum_bio_inv <- read.csv("data/crew_data_sep_sub_sum_bio_inv.csv", fileEncoding="UTF-8")

################################# 
## Matson Field log volunteer 
volunteer_data_matson <- read.csv("data/MatsonMattocksFieldLog-2016-2024/Matson-Field-Log-2022-2025.csv", fileEncoding="UTF-8")
volunteer_data_matson$Date <- as.Date(volunteer_data_matson$Date)
str(volunteer_data_matson)
colnames(volunteer_data_matson)

################################# 
# Cover data
cover_data <- read.csv("data/HAT_cover_mean.csv", fileEncoding="UTF-8")

################################# 
# Species counts
species_count <- read.csv("data/species_counts.csv", fileEncoding="UTF-8")
```


```{r rename-site-location-worksite-columns-for-sd-group, include = FALSE}
#############################################
# Sites Data
HAT_sites_HAT
colnames(HAT_sites_HAT)
HAT_sites_HAT$FullName <- HAT_sites_HAT$Site
HAT_sites_HAT$Site <- gsub("Matson Conservation Area", "Matson", HAT_sites_HAT$Site)
HAT_sites_HAT$Site <- gsub("Oak Haven Park", "Oak Haven", HAT_sites_HAT$Site)
HAT_sites_HAT$Site <- gsub("Havenwood Park", "Havenwood", HAT_sites_HAT$Site)

#############################################
# Round metrics values to 1 decimal
str(HAT_sites_HAT)
HAT_sites_HAT$Hours_per_Biomass_2022 <- sprintf("%.1f", HAT_sites_HAT$Hours_per_Biomass_2022)
HAT_sites_HAT$Hours_per_Biomass_2023 <- sprintf("%.1f", HAT_sites_HAT$Hours_per_Biomass_2023)
HAT_sites_HAT$Hours_per_Biomass_2024 <- sprintf("%.1f", HAT_sites_HAT$Hours_per_Biomass_2024)
HAT_sites_HAT$Hours_per_Biomass_2025 <- sprintf("%.1f", HAT_sites_HAT$Hours_per_Biomass_2025)
HAT_sites_HAT$Crew_Hours_2022 <- sprintf("%.1f", HAT_sites_HAT$Crew_Hours_2022)
HAT_sites_HAT$Crew_Hours_2023 <- sprintf("%.1f", HAT_sites_HAT$Crew_Hours_2023)
HAT_sites_HAT$Crew_Hours_2024 <- sprintf("%.1f", HAT_sites_HAT$Crew_Hours_2024)
HAT_sites_HAT$Crew_Hours_2025 <- sprintf("%.1f", HAT_sites_HAT$Crew_Hours_2025)
HAT_sites_HAT$Biomass_2022 <- sprintf("%.1f", HAT_sites_HAT$Biomass_2022)
HAT_sites_HAT$Biomass_2023 <- sprintf("%.1f", HAT_sites_HAT$Biomass_2023)
HAT_sites_HAT$Biomass_2024 <- sprintf("%.1f", HAT_sites_HAT$Biomass_2024)
HAT_sites_HAT$Biomass_2025 <- sprintf("%.1f", HAT_sites_HAT$Biomass_2025)
HAT_sites_HAT$Area_2022 <- sprintf("%.1f", HAT_sites_HAT$Area_2022)
HAT_sites_HAT$Area_2023 <- sprintf("%.1f", HAT_sites_HAT$Area_2023)
HAT_sites_HAT$Area_2024 <- sprintf("%.1f", HAT_sites_HAT$Area_2024)
HAT_sites_HAT$Area_2025 <- sprintf("%.1f", HAT_sites_HAT$Area_2025)
str(HAT_sites_HAT)

#############################################
# Crew Data
# Summary data totals per year per site
crew_data_sep_sub_sum_by_group_site_rename_site <- crew_data_sep_sub_sum_by_group_site_1 %>%
  rename(Site = Work_Site)

crew_data_sep_sub_sum_by_group_site_rename_site$Site <- gsub("Matson Conservation Area", "Matson", crew_data_sep_sub_sum_by_group_site_rename_site$Site)
crew_data_sep_sub_sum_by_group_site_rename_site$Site <- gsub("Oak Haven Park", "Oak Haven", crew_data_sep_sub_sum_by_group_site_rename_site$Site)
crew_data_sep_sub_sum_by_group_site_rename_site$Site <- gsub("Havenwood Park", "Havenwood", crew_data_sep_sub_sum_by_group_site_rename_site$Site)

#############################################
write.csv(crew_data_sep_sub_sum_by_group_site_rename_site, "data/crew_data_sep_sub_sum_by_group_site_rename_site.csv")

crew_data_sep_sub_sum_bio_inv_rename_site <- crew_data_sep_sub_sum_bio_inv %>%
  rename(Site = Work_Site)

crew_data_sep_sub_sum_bio_inv_rename_site$Site <- gsub("Matson Conservation Area", "Matson", crew_data_sep_sub_sum_bio_inv_rename_site$Site)
crew_data_sep_sub_sum_bio_inv_rename_site$Site <- gsub("Oak Haven Park", "Oak Haven", crew_data_sep_sub_sum_bio_inv_rename_site$Site)

crew_data_sep_sub_sum_bio_inv_rename_site$Site <- gsub("Havenwood Park", "Havenwood", crew_data_sep_sub_sum_bio_inv_rename_site$Site)

# Top 5 Invasive Species
colnames(crew_data_sep_sub_sum_bio_inv_rename_site)
unique(crew_data_sep_sub_sum_bio_inv_rename_site$Invasive_Species_Cleared)

crew_data_sep_sub_sum_bio_inv_rename_site <- crew_data_sep_sub_sum_bio_inv_rename_site %>% relocate(Year, Site, Area_Cleared_m2, Biomass_Removed_m3, Invasive_Species_Cleared, Crew_Hours, Work_Volunteer, Data_Change_Assumptions)

crew_data_sep_sub_sum_bio_inv_top5 <- crew_data_sep_sub_sum_bio_inv_rename_site %>% filter(Invasive_Species_Cleared %in% c("daphne", "English ivy",  "Himalayan blackberry", "Scotch broom", "shiny geranium"))

#############################################
## Matson Field log volunteer 
str(volunteer_data_matson)
colnames(volunteer_data_matson)
volunteer_data_matson_sub <- subset(volunteer_data_matson, select = -c(1,4,6,8,11,14,17:21))
colnames(volunteer_data_matson_sub)

colnames(crew_data_sep_sub_sum_bio_inv_rename_site)

# change column order to same as volunteer_data_matson
colnames(crew_data_sep_sub_1_filtered)
#crew_data_sep_sub_1_filtered <- subset(crew_data_sep_sub_1_filtered, select = -c(3))
crew_data_sep_sub_1_filtered <- crew_data_sep_sub_1_filtered %>%
  relocate(Year, Date, Site, Area_Cleared_m2, Biomass_Removed_m3, Invasive_Species_Cleared, Native_or_Invasive, Crew_Hours, Work_Volunteer, Data_Change_Assumptions)
colnames(crew_data_sep_sub_1_filtered)

volunteer_data_matson_sub <- volunteer_data_matson_sub %>% relocate(Year, Date, Site, Area_Cleared_m2, Biomass_Removed_m3, Invasive_Species_Cleared, Native_or_Invasive, Crew_Hours, Work_Volunteer, Data_Change_Assumptions)
colnames(volunteer_data_matson_sub)

#############################################
# rbind work and volunteer
crew_vol <- rbind(crew_data_sep_sub_1_filtered, volunteer_data_matson_sub)

write.csv(crew_vol, "data/crew_vol.csv")

unique(crew_vol$Native_or_Invasive)
crew_vol_grs <- crew_vol[crew_vol$Native_or_Invasive == "MixedGrass",]
crew_vol_inv <- crew_vol[crew_vol$Native_or_Invasive == "Invasive",]

#############################################
crew_vol_inv_top5 <- crew_vol %>% filter(Invasive_Species_Cleared %in% c("daphne", "English ivy",  "Himalayan blackberry", "Scotch broom", "shiny geranium"))

colnames(crew_vol_inv_top5)

#############################################
  crew_vol_inv_top5_sum <- crew_vol_inv_top5 %>%
  group_by(Site, Year, Invasive_Species_Cleared) %>%
  summarise(Biomass_Removed_m3 = sum(Biomass_Removed_m3), 
            Crew_Hours = sum(Crew_Hours),
            Area_Cleared_m2 = sum(Area_Cleared_m2)
            )
crew_vol_inv_top5_sum
# Check to ensure unique values of Invasive Species Cleared

#############################################
# Save Calculation subset
write.csv(crew_vol_inv_top5_sum, "data/crew_vol_inv_top5_sum.csv", row.names = FALSE)

#############################################
# Cover Data
cover_data_rename_site <- cover_data %>%
  rename(Site = Location)

cover_data_rename_site$Site <- gsub("Matson Conservation Area", "Matson", cover_data_rename_site$Site)
cover_data_rename_site$Site <- gsub("Oak Haven Park", "Oak Haven", cover_data_rename_site$Site)
cover_data_rename_site$Site <- gsub("Havenwood Park", "Havenwood", cover_data_rename_site$Site)

colnames(cover_data_rename_site)
cover_data_rename_site_sub <- subset(cover_data_rename_site, select = -c(9,10,11))

cover_data_rename_site_sub$Date <- as.Date(cover_data_rename_site_sub$Date)

## Add upper and lower bounds mean +/- sd

cover_data_rename_site_sub <- cover_data_rename_site_sub %>% 
                                      mutate(lower = mean_value - sd_value)

cover_data_rename_site_sub <- cover_data_rename_site_sub %>% 
                                      mutate(upper = mean_value + sd_value)

str(cover_data_rename_site_sub)

## ROund all numbers to 2 decimals
cover_data_rename_site_sub <- cover_data_rename_site_sub %>%
  mutate(across(where(is.numeric), round, 2))


## THis seems to mess up the charts ???
# cover_data_rename_site_sub$upper <- sprintf("%.2f", cover_data_rename_site_sub$upper)
# cover_data_rename_site_sub$lower <- sprintf("%.2f", cover_data_rename_site_sub$lower)

#############################################
cov_nat_top5 <- cover_data_rename_site_sub %>% filter(Species %in% c("camas", "delphinium",  "Pacific sanicle", "licorice fern", "Oregon grape"))

#############################################
unique(cover_data_rename_site_sub$Native_or_Invasive)
cover_data_rename_site_sub_grs <- cover_data_rename_site_sub[cover_data_rename_site_sub$Native_or_Invasive == "MixedGrass",]
cover_data_rename_site_sub_inv <- cover_data_rename_site_sub[cover_data_rename_site_sub$Native_or_Invasive == "Invasive",]
cover_data_rename_site_sub_nat <- cover_data_rename_site_sub[cover_data_rename_site_sub$Native_or_Invasive == "Native",]

cover_data_rename_site_sub_nat_t <- cover_data_rename_site_sub_nat[cover_data_rename_site_sub_nat$Treated == "Treated",]
cover_data_rename_site_sub_nat_u <- cover_data_rename_site_sub_nat[cover_data_rename_site_sub_nat$Treated == "Untreated",]
cover_data_rename_site_sub_inv_t <- cover_data_rename_site_sub_inv[cover_data_rename_site_sub_inv$Treated == "Treated",]
cover_data_rename_site_sub_inv_u <- cover_data_rename_site_sub_inv[cover_data_rename_site_sub_inv$Treated == "Untreated",]

#############################################
# Top Invasive Species
crew_data_sep_sub_sum_bio_inv_top5 <- crew_data_sep_sub_sum_bio_inv_rename_site %>% filter(Invasive_Species_Cleared %in% c("daphne", "English ivy",  "Himalayan blackberry", "Scotch broom", "shiny geranium"))

#############################################
# drop unknown species
species_count <- species_count[-c(25), ]
species_count <- species_count %>%
  rename(Site = Location)
```

```{r shared-data, include = FALSE}
### Create sharable database using Crosstalk package
#############################################
# crew_data_sep_sub.csv 238 obs 9 variable
sd_crew_vol <- SharedData$new(data = crew_vol, group = "crew_all_group")

sd_crew_vol_grs <- SharedData$new(data = crew_vol_grs, group = "crew_all_group")
sd_crew_vol_inv <- SharedData$new(data = crew_vol_inv, group = "crew_all_group")

sd_crew_vol_inv_top5 <- SharedData$new(data = crew_vol_inv_top5, group = "top5_group_bar")

crew_vol_inv_top5_sum <- SharedData$new(data = crew_vol_inv_top5_sum, group = "top5_group_facet")

#############################################
# Summary data totals per year per site
# used in Invasive Biomass charts
sd_crew <- SharedData$new(data = crew_data_sep_sub_sum_by_group_site_rename_site, group = "crew_group")
# crew_data_sep_sub_sum_bio_inv.csv

#############################################
sd_cover <- SharedData$new(data = cover_data_rename_site_sub, group = "cover_group")

sd_cov_nat_top5 <- SharedData$new(data = cov_nat_top5, group = "cover_group")

sd_cover_grs <- SharedData$new(data = cover_data_rename_site_sub_grs, group = "cover_group")
sd_cover_inv <- SharedData$new(data = cover_data_rename_site_sub_inv, group = "cover_group")
sd_cover_nat <- SharedData$new(data = cover_data_rename_site_sub_nat, group = "cover_group")

sd_cover_nat_t <- SharedData$new(data = cover_data_rename_site_sub_nat_t, group = "cover_group")
sd_cover_nat_u <- SharedData$new(data = cover_data_rename_site_sub_nat_u, group = "cover_group")
sd_cover_inv_t <- SharedData$new(data = cover_data_rename_site_sub_inv_t, group = "cover_group")
sd_cover_inv_u <- SharedData$new(data = cover_data_rename_site_sub_inv_u, group = "cover_group")

#############################################
sd_count <- SharedData$new(data = species_count, group = "count_group")

#############################################
sd_sites <- SharedData$new(data = HAT_sites_HAT, group = "crew_group")### Create sharable database using Crosstalk package
```


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

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

```{r about-tabs}
#############################################
HTML("<img src='images/HAT-logo-ss.png', width=150>")
# HTML("<img src='https://images.squarespace-cdn.com/content/v1/5e3c5b7e5460c55405a6d4d6/a8c2fb30-96fd-4042-925f-e76c7040dce6/Black+Logo+2.png?format=5w'>")

#############################################
h4("RNS ER390 Project for Visualizing HAT Monitoring Data")
hr(style = "border: 0.5px solid grey; width: 100%; margin: auto;")
HTML("
  <br>This interactive data visualization tool was created as a final project for University of Victoria Restoration of Natural Ecosystems ER390, with HAT as a community partner, and supervised by Nancy Shackelford.<br><br>
  ")
hr(style = "border: 0.5px solid grey; width: 100%; margin: auto;")
br()
#############################################
HTML("<strong>Created and Coded for HAT by Wendy Anthony</strong><br>
<span style='font-size:75%';>wanthony@uvic.ca
<br>
2026-02-02 07:17</span>")
br()
br()
hr(style = "border: 0.5px solid grey; width: 100%; margin: auto;")
```

Row  {data-height=1}
-----------------------------------------------

### ***About this Interactive Web Visualization Tool***


Row  {.tabset .tabset-fade}
-------------------------------------

### HAT Datasets
```{r}
HTML("
       <h5>HAT Data of 9 HAT-only-Managed-Sites</h5>
     
     1. <strong>HAT Restoration Crew Site Data</strong> 
     <br> * <strong>Metrics</strong>: daily crew hours, daily invasive species removed (cubic metres); yearly crew hours, yearly invasive species removed (cubic metres)
     <br> * <strong>Sites</strong>: Bear Hill, Calypso Woods, Camas Hill, Funk, Havenwood, Matson, Oak Haven, Purple Sanicle, Yates, 
     <br> * <strong>Datasets</strong>: <em>Restoration Crew Data.xlsx</em>: Apr 2022-Sep 2025; Sites Daily; Sites Yearly; Top Invasives Site
     <br><br>
     
     2. <strong>Matson Mattocks Field Logs</strong> 
     <br> * <strong>Metrics</strong>: daily volunteer work hours, daily volunteer invasive species removal
     <br> * <strong>Sites</strong>: added to Matson Work Crew data
     <br> * <strong>Datasets</strong>: <em>Matson Mattocks Field Logs</em>: Apr 2022-Sep 2025; Sites Daily; Top Invasives Site
     <br><br>
     
     3. <strong>Cover Data 2024-2025</strong>  
     <br> * <strong>Metrics</strong>: cover, species
     <br> * <strong>Sites</strong>: Matson, Oak Haven
     <br> * <strong>Datasets</strong>: <em>Cover Data 2024-2025</em>: Cover Mean % (Native/Invasive & Treated/Untreated); Species Richness
     <br><br>
     
     4. <strong>Site Data</strong> 
     <br> * <strong>Metrics</strong>: Map Location; Apr 2022-Sep 2025; Top 5 invasives, Hours per m3 Biomass, staff hours, biomass removed
     <br> * <strong>Sites</strong>: Havenwood, Matson, Oak Haven
     <br> * <strong>Data</strong>: <em>https://hat.bc.ca/community-based-restoration</em>
     <br><br>
     ")
```


### How to Use This Interactive Tool
```{r}
HTML("
       <h5>How to use this interactive data visualization tool</h5>
  <strong>Top Header Navigation Pages</strong><br>
  * Navigation links in the top header host different data visualization charts and datatables<br>
  * Each link uses a different dataset and is responsive to different filters<br><br>
  
  <strong>Filters</strong><br>
  * All years and sites are shown until data is filtered<br>
  * Filters must be cleared, using delete or backspace key in order to start new filter<br>
  * Filtered summary statistics accompany each data set<br><br>

  <strong>Interactive Visualizations</strong><br>
  * Hover over data visualizations to view tooltips<br>
  * Data visualization can be zoom-focused by using a 'click-drag' over a certain area<br>
  * Double-click within chart to return to original version<br>
  * If all else fails, refresh webpage in browser
     ")
```

### Tips for Analyzing Chart Visualizations
```{r}
HTML("
  <h5>What Story Is Being Told By The Data Visualizations</h5>
    <strong>Notice any Patterns Trends?</strong><br>
    * Over Years<br>
    * Between Species<br>
    * Same Site<br>
    <br>
    <strong>If Hours and Biomass trend down, is it worth still sending crew out?</strong><br>
    * How important is regular maintenance of removing Invasives?<br>
    * Is there a threshold of amount of biomass removed to justify Crew Hours?<br>
     ")
    # <br>
    # <strong></strong><br>
    # * <br>
    # <br>
    # <strong></strong><br>
    # * <br>
    # <br>
    # <strong></strong><br>
    # * <br>
```

### ER390 Project Proposal
```{r}
HTML("
<strong>Background Research</strong><br> 
* Comparing monitoring restoration projects using consistent vegetation measurements techniques, may help identify responses to stressors affecting already compromised and rare GOE.<br> 
* Visually representing data helps make complex data understandable, reveals patterns, creates 'data-based story-telling', and communicates insights for making effective management decisions.<br> 
* RMarkdown-generated reports can help create reproducible research.
<br><br>

<strong>Project Goals and Overall Purpose</strong><br>
* To create an interactive data visualization tool for non-coders, based on HAT's needs, with tutorial instructions<br>
* Use open-source R code to format monitoring data collected at multiple HAT sites, to communicate data information and patterns.
<br><br>

<strong>Project Objectives</strong><br>
* Analyze and transform collected data<br>
* Write reproducible data visualization code<br>
* Create interactive, browser-based Data Visualization Tool<br>
* Analyze resulting patterns<br><br>

<strong>RStudio-created Project Deliverables</strong><br>
* RMarkdown Data Processing Document Tool using best practises for data<br>
* Interactive Browser-based Data Visualizations Tool with Tutorial for Use<br>
* Written Report: Due 2026-04-15; publish in online RNS Ecorestoration journal<br>
* Project Presentation: By mid-May 2026
  ")
```


  Sites Daily
=====================================  

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

```{r filter-crew-hours-all}
#############################################
htmltools::br()
h4("Filtered Statistics")
#p(class = "container", class = "value", summarywidget(sd_crew_vol, column = "Crew_Hours", statistic = "sum"), span(class = "caption", "= hours of labor"))
p(class = "container", class = "value", summarywidget(sd_crew_vol, column = "Crew_Hours", statistic = "sum"), span(class = "caption", " = Crew Hours", digits = 2))
p(class = "container", class = "value", summarywidget(sd_crew_vol, column = "Biomass_Removed_m3", statistic = "sum", digits = 2), span(class = "caption", " = Biomass Removed (m3)"))
p(class = "container", class = "value", summarywidget(sd_crew_vol, column = "Area_Cleared_m2", statistic = "sum", digits = 2), span(class = "caption", " = Area Cleared (m2)"))

htmltools::br()
htmltools::hr(style = "border: 0.5px solid grey; width: 250px; margin: auto;")

#############################################
h4("Filters")
strong(em("Tip: Start by choosing a site"))
br()
br()
p("Note: Density plots only respond to Site filter")
# Create a filter input
filter_select(id = "Site", label = "Choose Site", sharedData = sd_crew_vol, group = ~Site, multiple = T)
filter_checkbox(id = "Year", label = "Choose Year", sharedData = sd_crew_vol, group = ~Year, allLevels = TRUE)
# filter_slider(id = "Year", label = "Choose Date Span", sharedData = sd_crew_vol, column = ~Year,  step = 1)
filter_select(id = "Invasive_Species_Cleared", label = "Choose Species", sharedData = sd_crew_vol, group = ~Invasive_Species_Cleared, allLevels = TRUE)
filter_select(id = "Work_Volunteer", label = "Choose Work or Volunteer", sharedData = sd_crew_vol, group = ~Work_Volunteer, multiple = T)
filter_select(id = "Native_or_Invasive", label = "Choose Invasive or MixedGrass", sharedData = sd_crew_vol, group = ~Native_or_Invasive, multiple = T)

#############################################
htmltools::br()
htmltools::HTML("<strong>Data Source:</strong> <em>HAT Restoration Crew Data.xlsx</em>")
htmltools::br()
htmltools::br()
htmltools::hr(style = "border: 0.5px solid grey; width: 250px; margin: auto;")
htmltools::br()
# HTML("<img src='https://images.squarespace-cdn.com/content/v1/5e3c5b7e5460c55405a6d4d6/a8c2fb30-96fd-4042-925f-e76c7040dce6/Black+Logo+2.png?format=5w'>")
HTML("<img src='images/HAT-logo-ss.png', width = 100>")
htmltools::br()
htmltools::br()
```

Row  {data-height=75}
-----------------------------------------------

### ***Crew (& Matson Volunteer) Data for hours worked & biomass cleared***
```{r}
htmltools::HTML("
<strong>Daily crew data</strong> was collected for work hours, invasive species, and biomass removed.<br>
<em>Note: Some missing data for fall 2025</em>. <strong><em>Tip: Start by choosing a site</em></strong>.. 
")
```

Row  {.tabset .tabset-fade}
-------------------------------------

### **Hours by Year** 
```{r inv-hours-scatter-year}
#############################################
custom_colours_Site_9 <- c(
			"Matson" = "#f8766d", 
      "Oak Haven" = "#619cff",
			"Purple Sanicle" = "#db72fb",
			"Yates" = "#ff61c3",
			"Funk" = "#00ba38",
			"Havenwood" = "#00c19f",
			"Bear Hill" = "#00b9e3",
			"Camas Hill" = "#93aa00",
			"Calypso Woods" = "#f2cb0a"
)

#############################################
ggplotly(
  ggplot(sd_crew_vol_inv, aes(x = Date, y = Crew_Hours, color = Site, 
                              text = paste("Year:", Year,
                                           "\nDate:", Date,
                                           "\nCrew Hours:", Crew_Hours,
                                           "\nWork or Volunteer:", Work_Volunteer,
                                           "\nSite:", Site,
                                           "\nInvasive Species:", Invasive_Species_Cleared,
                                           "\nBiomass Removed (cubic metres):", Biomass_Removed_m3,
                                           "\nArea of Biomass Removed (square metres):", Area_Cleared_m2))) + 
  geom_point() +
  theme_minimal() + #get rid of grey background and tick marks
  theme(legend.position ="bottom") + 
  theme(axis.text.x = element_text(angle = 0, vjust = 1, hjust=1, size = 9)) +
  theme(axis.text.y = element_text(size = 9)) +  
  # aligns title to left
  theme(plot.title = element_text(hjust = 0)) +
   # scale_color_manual(values = c("#b15928","#ffff99","#6a3d9a","#cab2d6","#ff7f00","#33a02c","#a6cee3","#b2df8a", "#cab2d6")) +
  scale_color_manual(values = custom_colours_Site_9) +
        labs(title='Daily Hours to Remove Biomass by HAT Crew & Volunteers',
          x = "Date", y = "Crew Hours",
          color = ""), 
  tooltip = "text",
  config = (displayModeBar = False) 
  ) %>%
    layout(legend = list(
      orientation = "h",
      xanchor="center",
      x = 0.5,
      # gives some space between x axis label and legend
      y = -0.2
    ))
```


### **Biomass by Year** 
```{r inv-biomass-scatter-year}
#############################################
custom_colours_Site_9 <- c(
			"Matson" = "#f8766d", 
      "Oak Haven" = "#619cff",
			"Purple Sanicle" = "#db72fb",
			"Yates" = "#ff61c3",
			"Funk" = "#00ba38",
			"Havenwood" = "#00c19f",
			"Bear Hill" = "#00b9e3",
			"Camas Hill" = "#93aa00",
			"Calypso Woods" = "#f2cb0a"
)

#############################################
ggplotly(
  ggplot(sd_crew_vol_inv, aes(x = Date, y = Biomass_Removed_m3, color = Site,
                              text = paste("Year:", Year,
                                           "\nDate:", Date,
                                           "\nCrew Hours:", Crew_Hours,
                                           "\nWork or Volunteer:", Work_Volunteer,
                                           "\nSite:", Site,
                                           "\nInvasive Species:", Invasive_Species_Cleared,
                                           "\nBiomass Removed (cubic metres):", Biomass_Removed_m3,
                                           "\nArea of Biomass Removed (square metres):", Area_Cleared_m2))) + 
  geom_point() +
  theme_minimal() + #get rid of grey background and tick marks
  theme(legend.position ="bottom") + 
  theme(axis.text.x = element_text(angle = 0, vjust = 1, hjust=1, size = 9)) +
  theme(axis.text.y = element_text(size = 9)) +  
  # aligns title to left
  theme(plot.title = element_text(hjust = 0)) +
  #scale_color_manual(values = c("#b15928","#ffff99","#6a3d9a","#cab2d6","#ff7f00","#33a02c","#a6cee3","#b2df8a", "#cab2d6")) +
   scale_color_manual(values = custom_colours_Site_9) +
        labs(title='Daily Biomass Removed by HAT Crew & Volunteers',
          x = "Date",
          y = "Biomass Removed (cubic metres)",
          color = ""), 
  tooltip = "text",
  config = (displayModeBar = False) 
  ) %>%
    layout(legend = list(
      orientation = "h",
      xanchor="center",
      x = 0.5,
      # gives some space between x axis label and legend
      y = -0.2
    ))
```

### **Area of Biomass by Year** 
```{r inv-biomass-scatter-year-area}
#############################################
custom_colours_Site_9 <- c(
			"Matson" = "#f8766d", 
      "Oak Haven" = "#619cff",
			"Purple Sanicle" = "#db72fb",
			"Yates" = "#ff61c3",
			"Funk" = "#00ba38",
			"Havenwood" = "#00c19f",
			"Bear Hill" = "#00b9e3",
			"Camas Hill" = "#93aa00",
			"Calypso Woods" = "#f2cb0a"
)

#############################################
ggplotly(
  ggplot(sd_crew_vol_inv, aes(x = Date, y = Area_Cleared_m2, color = Site,
                              text = paste("Year:", Year,
                                           "\nDate:", Date,
                                           "\nCrew Hours:", Crew_Hours,
                                           "\nWork or Volunteer:", Work_Volunteer,
                                           "\nSite:", Site,
                                           "\nInvasive Species:", Invasive_Species_Cleared,
                                           "\nBiomass Removed (cubic metres):", Biomass_Removed_m3,
                                           "\nArea of Biomass Cleared (square metres):", Area_Cleared_m2)
                              )) + 
  geom_point() +
  theme_minimal() + #get rid of grey background and tick marks
  theme(legend.position ="bottom") + 
  theme(axis.text.x = element_text(angle = 0, vjust = 1, hjust=1, size = 9)) +
  theme(axis.text.y = element_text(size = 9)) +  
  # aligns title to left
  theme(plot.title = element_text(hjust = 0)) +
   scale_color_manual(values = custom_colours_Site_9) +
        labs(title='Area of Biomass Removed Daily by HAT Crew & Volunteers',
          x = "Date",
          y = "Area of Biomass Removed (square metres)",
          color = ""), 
  tooltip = "text",
  config = (displayModeBar = False) 
  ) %>%
    layout(legend = list(
      orientation = "h",
      xanchor="center",
      x = 0.5,
      # gives some space between x axis label and legend
      y = -0.2
    ))
```

### Datatable
```{r data-table-combine-all}
htmltools::h5("Daily Crew Hours (& Volunteer) & Biomass Datatable")
htmltools::br()
 datatable(sd_crew_vol, rownames = FALSE, class = 'compact',
           extensions = c("Buttons"),
           options = list(dom = 'Bfrtip',
                         buttons = list(
                        'colvis',
                        list(
                          extend = 'csv',
                          filename = paste0("HAT-Restoration-Site-Daily-Data-", Sys.Date())
                        ),
                        list(
                          extend = 'excel',
                          filename = paste0("HAT-Restoration-Site-Daily-Data-", Sys.Date())
                        ),
                        list(
                          extend = 'print',
                          title = 'HAT Restoration Daily Site Data' # Change title here
                        )
                          ),
                        # removed previous / next buttons
                         paging = FALSE, 
                    # centre contents of columns 4,5 8
                         columnDefs = list(list(className = 'dt-center', targets = c(3,4,7))
                            )
           ))
```


  Sites Yearly
=====================================  

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

```{r filter-crew-hours-biomass-inv-sp}
#############################################
htmltools::br()
htmltools::br()
h4("Filtered Statistics")
p(class = "container", class = "value", summarywidget(sd_crew, column = "Crew_Hours", statistic = "sum"), span(class = "caption", "= Crew hours", digits = 2))
p(class = "container", class = "value", summarywidget(sd_crew, column = "Biomass_Removed_m3", statistic = "sum"), span(class = "caption", "= m3 Biomass Removed", digits = 2))
p(class = "container", class = "value", summarywidget(sd_crew, column = "Area_Cleared_m2", statistic = "sum", digits = 2), span(class = "caption", " = Area Cleared (m2)"))
htmltools::br()
htmltools::hr(style = "border: 0.5px solid grey; width: 250px; margin: auto;")

#############################################
h4("Filters")
# Create a filter input
filter_select(id = "Site", label = "Choose Site", sharedData = sd_crew, group = ~ Site, multiple = T)
filter_checkbox(id = "Year", label = "Choose Year", sharedData = sd_crew, group = ~ Year, allLevels = TRUE)
htmltools::br()
htmltools::HTML("<strong>Data Source:</strong> <em>HAT Restoration Crew Data.xlsx</em>")
htmltools::br()
htmltools::br()
htmltools::hr(style = "border: 0.5px solid grey; width: 250px; margin: auto;")
htmltools::br()

#############################################
HTML("<img src='images/HAT-logo-ss.png', width = 100>")
htmltools::br()
htmltools::br()
```

Row  {data-height=55}
-----------------------------------------------

### ***Crew Data Summarized***
```{r}
htmltools::HTML("
  <strong>Yearly summary</strong> of daily data collected for crew hours, invasive species and biomass removed. Hours required per cubic metre of biomass shows labour cost. <em>Note: Some missing data for fall 2025</em>")
```

Row  {.tabset .tabset-fade}
-------------------------------------

### Crew Hours 

```{r crew-hrs-site, echo = FALSE, message = FALSE, warning = FALSE, height = 7}
#############################################
custom_colours_years <- c("2022" = "#ffff33", 
                    "2023" = "#4daf4a", 
                    "2024" = "#984ea3", 
                    "2025" = "#ff7f00")

#############################################
## NOTE  ggplot needs to be wrapped in ggplotly for crosstalk to work
ggplotly(
  ggplot(sd_crew, 
   aes(x = reorder(Site, desc(Site)), y = Crew_Hours, fill = as.factor(Year), text = paste("Year:", Year,
                                                          "\nSite:", Site,
                                                          "\nCrew Hours:", Crew_Hours,      
                                                          "\nBiomass Removed (cubic metres):", Biomass_Removed_m3,  
                                                          "\nArea Cleared (square metres):", Area_Cleared_m2,
                                                          "\nLabour Cost Hr/Bio Ratio:", Labour_Hr_Bio_Ratio,
                                                          "\nLabour Bio/Hr Ratio:", Labour_Bio_Hr_Ratio,
                                                          "\nArea/Bio Ratio:", Area_Bio_Ratio))) + 
  geom_bar(stat = "identity", width = 0.5, position = position_dodge2(padding = 0.2)) +
  coord_flip() + 
  theme_minimal() + #get rid of grey background and tick marks
  #theme(legend.position ="bottom") + 
  theme(axis.text.x = element_text(angle = 0, vjust = 1, hjust=1, size = 7)) +
    # aligns title to left
  theme(plot.title = element_text(hjust = 0)) +  
  scale_fill_manual(values = custom_colours_years) +
  labs(
        title = "Crew Hours Removing Invasive Species by Site",
        fill = "",
        x = "", y = "Crew Hours"), 
  tooltip = "text",
  config = (displayModeBar = False) 
  ) %>%
    layout(legend = list(orientation="h",
    xanchor="center",
    x = 0.5,
    # gives some space between x axis label and legend
    y = -0.2
    ))
```


### Biomass Removed

```{r crew-data-biomass, echo = FALSE, message = FALSE, warning = FALSE, height = "100%"}
#############################################
custom_colours_years <- c("2022" = "#ffff33", 
                    "2023" = "#4daf4a", 
                    "2024" = "#984ea3", 
                    "2025" = "#ff7f00")

#############################################
ggplotly(
  ggplot(sd_crew, 
   aes(x = reorder(Site, desc(Site)), y = Biomass_Removed_m3, fill = as.factor(Year), 
                                                          text = paste("Year:", Year,
                                                          "\nSite:", Site,
                                                          "\nCrew Hours:", Crew_Hours,      
                                                          "\nBiomass Removed (cubic metres):", Biomass_Removed_m3,  
                                                          "\nArea Cleared (square metres):", Area_Cleared_m2,
                                                          "\nLabour Cost Hr/Bio Ratio:", Labour_Hr_Bio_Ratio,
                                                          "\nLabour Bio/Hr Ratio:", Labour_Bio_Hr_Ratio,
                                                          "\nArea/Bio Ratio:", Area_Bio_Ratio))) + 
  geom_bar(stat = "identity", width = 0.5, position = position_dodge2(padding = 0.2)) +
  coord_flip() + 
  theme_minimal() + #get rid of grey background and tick marks
  # theme(legend.position ="bottom") + 
  scale_fill_manual(values = custom_colours_years) +
  theme(axis.text.x = element_text(angle = 0, vjust = 1, hjust=1, size = 7)) +
    # aligns title to left
  theme(plot.title = element_text(hjust = 0)) +  
        labs(
          title='Invasive Species Biomass (cubic metres) Removed by Site',
          fill = "",
          x = "", y = "Biomass Removed (cubic metres)"),
  tooltip = "text",
  config = (displayModeBar = False) 
  ) %>%
    layout(legend = list(orientation="h",
    xanchor="center",
    x = 0.5,
    # gives some space between x axis label and legend
    y = -0.2
    ))
```

### Area of Biomass Removed 

```{r crew-data-biomass-area, echo = FALSE, message = FALSE, warning = FALSE, height = "100%"}
#############################################
custom_colours_years <- c("2022" = "#ffff33", 
                    "2023" = "#4daf4a", 
                    "2024" = "#984ea3", 
                    "2025" = "#ff7f00")

#############################################
ggplotly(
  ggplot(sd_crew, 
   aes(x = reorder(Site, desc(Site)), y = Area_Cleared_m2, fill = as.factor(Year), 
                                                          text = paste("Year:", Year,
                                                          "\nSite:", Site,
                                                          "\nCrew Hours:", Crew_Hours,      
                                                          "\nBiomass Removed (cubic metres):", Biomass_Removed_m3,  
                                                          "\nArea Cleared (square metres):", Area_Cleared_m2,
                                                          "\nLabour Cost Hr/Bio Ratio:", Labour_Hr_Bio_Ratio,
                                                          "\nLabour Bio/Hr Ratio:", Labour_Bio_Hr_Ratio,
                                                          "\nArea/Bio Ratio:", Area_Bio_Ratio))) + 
  geom_bar(stat = "identity", width = 0.5, position = position_dodge2(padding = 0.2)) +
  coord_flip() + 
  theme_minimal() + #get rid of grey background and tick marks
  # theme(legend.position ="bottom") + 
  scale_fill_manual(values = custom_colours_years) +
  theme(axis.text.x = element_text(angle = 0, vjust = 1, hjust=1, size = 7)) +
    # aligns title to left
  theme(plot.title = element_text(hjust = 0)) +  
        labs(
          title='Area of Invasive Biomass (square metres) Removed by Site',
          fill = "",
          x = "", y = "Area of Biomass Removed (square metres)"),
  tooltip = "text",
  config = (displayModeBar = False) 
  ) %>%
    layout(legend = list(orientation="h",
    xanchor="center",
    x = 0.5,
    # gives some space between x axis label and legend
    y = -0.2
    ))
```



### Hours per Biomass
```{r crew-hrs-per-biomass-removed-ratio}
#############################################
custom_colours_years <- c("2022" = "#ffff33", 
                    "2023" = "#4daf4a", 
                    "2024" = "#984ea3", 
                    "2025" = "#ff7f00")

#############################################
ggplotly(
ggplot(sd_crew, aes(x = reorder(Site, desc(Site)), y = Labour_Hr_Bio_Ratio, fill = as.factor(Year), 
                                                          text = paste("Year:", Year,
                                                          "\nSite:", Site,
                                                          "\nCrew Hours:", Crew_Hours,
                                                          "\nBiomass Removed (cubic metres):", Biomass_Removed_m3,  
                                                          "\nLabour Cost Hr/Bio Ratio:", Labour_Hr_Bio_Ratio,
                                                          "\nLabour Bio/Hr Ratio:", Labour_Bio_Hr_Ratio,
                                                          "\nArea Cleared (square metres):", Area_Cleared_m2,
                                                          "\nArea/Bio Ratio:", Area_Bio_Ratio))) + 
  geom_bar(stat = "identity", width = 0.5, position = "dodge") +
  coord_flip() +    
  theme_minimal() + #get rid of grey background and tick marks
  theme(legend.position ="bottom") + 
  scale_fill_manual(values = custom_colours_years) +
  theme(axis.text.x = element_text(angle = 0, vjust = 1, hjust=1, size = 7)) + 
      # aligns title to left
  theme(plot.title = element_text(hjust = 0)) +
  labs(
       title='Crew Hours Required to Remove each cubic metre of Biomass (cost)',
      fill = "",
      x = "", 
    y = "Ratio of Crew Hours per cubic metre Biomass Removed"
    ) +
  theme(axis.text.x = element_text(angle = 0, vjust = 1, hjust=1, size = 7)), 
  tooltip = "text",
  config = (displayModeBar = False) 
  ) %>%
    layout(legend = list(orientation = "h",
    xanchor="center",
    x = 0.5,
    # gives some space between x axis label and legend
    y = -0.2
    ))
```

### Area per Biomass 
```{r crew-hrs-per-biomass-removed-ratio-area}
#############################################
custom_colours_years <- c("2022" = "#ffff33", 
                    "2023" = "#4daf4a", 
                    "2024" = "#984ea3", 
                    "2025" = "#ff7f00")

#############################################
ggplotly(
ggplot(sd_crew, aes(x = reorder(Site, desc(Site)), y = Area_Bio_Ratio, fill = as.factor(Year), 
                                                          text = paste("Year:", Year,
                                                          "\nSite:", Site,
                                                          "\nCrew Hours:", Crew_Hours,
                                                          "\nBiomass Removed (cubic metres):", Biomass_Removed_m3,
                                                          "\nArea Cleared (square metres):", Area_Cleared_m2,
                                                          "\nArea/Bio Ratio:", Area_Bio_Ratio,  
                                                          "\nLabour Cost Hr/Bio Ratio:", Labour_Hr_Bio_Ratio,
                                                          "\nLabour Bio/Hr Ratio:", Labour_Bio_Hr_Ratio))) + 
  geom_bar(stat = "identity", width = 0.5, position = "dodge") +
  coord_flip() +    
  theme_minimal() + #get rid of grey background and tick marks
  theme(legend.position ="bottom") + 
  scale_fill_manual(values = custom_colours_years) +
  theme(axis.text.x = element_text(angle = 0, vjust = 1, hjust=1, size = 7)) + 
      # aligns title to left
  theme(plot.title = element_text(hjust = 0)) +
  labs(
       title='Area (square metre) of each cubic metre of Biomass Removed',
      fill = "",
      x = "", 
    y = "Ratio of Area square metre per cubic metre Biomass Removed"
    ) +
  theme(axis.text.x = element_text(angle = 0, vjust = 1, hjust=1, size = 7)), 
  tooltip = "text",
  config = (displayModeBar = False) 
  ) %>%
    layout(legend = list(orientation = "h",
    xanchor="center",
    x = 0.5,
    # gives some space between x axis label and legend
    y = -0.2
    ))
```

### Datatable
```{r data-table-crew}
htmltools::h5("Yearly Crew Hours (& Volunteer) & Biomass Datatable")
htmltools::br()
 datatable(sd_crew, rownames = FALSE, class = 'compact',
           extensions = c("Buttons"),
           options = list(dom = 'Bfrtip',
                         buttons = list(                        
                        'colvis',
                        list(
                          extend = 'csv',
                          filename = paste0("HAT-Restoration-Site-Yearly-Data-", Sys.Date())
                        ),
                        list(
                          extend = 'excel',
                          filename = paste0("HAT-Restoration-Site-Yearly-Data-", Sys.Date())
                        ),
                        list(
                          extend = 'print',
                          title = 'HAT Restoration Yearly Site Data' # Change title here
                        )
                          ),
                        # removed previous / next buttons
                         paging = FALSE, 
             columnDefs = list(list(className = 'dt-center', targets = c(1:7))
           )))
```


  Top 5 Invasives Sites
=====================================  

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

```{r filter-crew-hours-biomass-inv-sp-top5-facet}
#############################################
htmltools::br()
htmltools::br()
h4("Filtered Statistics")
p(class = "container", class = "value", summarywidget(crew_vol_inv_top5_sum, column = "Crew_Hours", statistic = "sum", digits = 2), span(class = "caption", "= Crew Hours"))
p(class = "container", class = "value", summarywidget(crew_vol_inv_top5_sum, column = "Biomass_Removed_m3", statistic = "sum", digits = 2), span(class = "caption", "= Biomass Removed (m3)"))
p(class = "container", class = "value", summarywidget(crew_vol_inv_top5_sum, column = "Area_Cleared_m2", statistic = "sum", digits = 2), span(class = "caption", " = Area Cleared (m2)"))

htmltools::br()
htmltools::hr(style = "border: 0.5px solid grey; width: 250px; margin: auto;")

#############################################
h4("Filters")
# Create a filter input
filter_select(id = "Site", label = "Choose Site", sharedData = crew_vol_inv_top5_sum, group = ~ Site, multiple = T)
filter_checkbox(id = "Year", label = "Choose Year", sharedData = crew_vol_inv_top5_sum, group = ~ Year, allLevels = TRUE)
filter_select(id = "Invasive_Species_Cleared", label = "Choose Species", sharedData = crew_vol_inv_top5_sum, group = ~ Invasive_Species_Cleared, allLevels = TRUE)

#############################################
htmltools::br()
htmltools::HTML("<strong>Data Source:</strong> <em>HAT Restoration Crew Data.xlsx</em>")
htmltools::br()
htmltools::br()
htmltools::hr(style = "border: 0.5px solid grey; width: 250px; margin: auto;")
htmltools::br()
# HTML("<img src='https://images.squarespace-cdn.com/content/v1/5e3c5b7e5460c55405a6d4d6/a8c2fb30-96fd-4042-925f-e76c7040dce6/Black+Logo+2.png?format=5w'>")
HTML("<img src='images/HAT-logo-ss.png', width = 100>")
htmltools::br()
htmltools::br()
```

Row  {data-height=55}
-----------------------------------------------

### ***Top 5 Invasive Species Biomass by Site***
```{r}
htmltools::HTML("
Multiple facets compare 8 sites for invasive species biomass removed (Bear Hill didn't differentiate any species from 'mixed species', thus doesn't show). <em>Note: Some missing data for fall 2025</em> 
  ")
```

Row  {.tabset .tabset-fade}
-------------------------------------

### **Top 5 Invasives by Site**
```{r inv-sp-biomass-top5-facet-site}
#############################################
custom_colours_years <- c("2022" = "#ffff33", 
                    "2023" = "#4daf4a", 
                    "2024" = "#984ea3", 
                    "2025" = "#ff7f00")

#############################################
ggplotly(
  ggplot(crew_vol_inv_top5_sum, aes(x = reorder(Invasive_Species_Cleared, desc(Invasive_Species_Cleared)), y = Biomass_Removed_m3, fill = as.factor(Year), 
    # fill = as.factor(Year) gives legend a colour vs a continuous variable colour
                                                          text = paste("Year:", Year,
                                                          "\nSite:", Site,
                                                          "\nInvasive Species Cleared:", Invasive_Species_Cleared,      
                                                          "\nCrew Hours:", Crew_Hours,
                                                          "\nBiomass Removed (cubic metres):", Biomass_Removed_m3,  
                                                          "\nArea Cleared (m2):", Area_Cleared_m2))) + 
  geom_bar(stat = "identity", width = 0.6, position = position_dodge(0.7)) +
  facet_wrap(vars(Site)) +
  coord_flip() + 
  theme_minimal() + #get rid of grey background and tick marks
    # needs to be below first theme
  theme(strip.background = element_rect(color = "black", fill = "#b5c0c1", size = 0.5, linetype = "solid"),
        strip.text = element_text(size = 11)) +
  theme(legend.position ="bottom") + 
    scale_fill_manual(values = custom_colours_years) +
      labs(
          title = "Top 5 Invasive Species Biomass (m3) Removed", 
          x = "",   
          y = "Biomass Removed (cubic metres)",   
          fill = ""
          ) +
  theme(axis.text.x = element_text(angle = 0, vjust = 1, hjust=1, size = 7)) +
    # aligns title to left
  theme(plot.title = element_text(hjust = 0)) +
    scale_y_continuous(breaks=c(0,10,20,30,40,50,60,70,80,90)), 
  
  tooltip = "text",
  config = (displayModeBar = False) 
  )
```

### Datatable Daily
```{r data-table-combine-top5}
htmltools::h5("Daily Crew Hours (& Volunteer) & Top 5 Species Biomass Datatable")
htmltools::br()
 datatable(sd_crew_vol_inv_top5, rownames = FALSE, class = 'compact',
           extensions = c("Buttons"),
           options = list(dom = 'Bfrtip',
                         buttons = list(
                        'colvis',
                        list(
                          extend = 'csv',
                          filename = paste0("HAT-Restoration-Site-Invasives-Daily-Data-", Sys.Date())
                        ),
                        list(
                          extend = 'excel',
                          filename = paste0("HAT-Restoration-Site-Invasives-Daily-Data-", Sys.Date())
                        ),
                        list(
                          extend = 'print',
                          title = 'HAT Restoration Invasives Daily Site Data' # Change title here
                        )
                          ),
                        # removed previous / next buttons
                         paging = FALSE, 
                    # centre contents of columns 4,5 8
                         columnDefs = list(list(className = 'dt-center', targets = c(0,1,3,4,7))
                            )
           ))
```

  
### Datatable Yearly
```{r data-table-combine-top5-facet}
htmltools::h5("Yearly Crew Hours (& Volunteer) Hours & Top 5 Species Biomass Datatable")
htmltools::br()
 datatable(crew_vol_inv_top5_sum, rownames = FALSE, class = 'compact',
           extensions = c("Buttons"),
           options = list(dom = 'Bfrtip',
                         buttons = list(
                        'colvis',
                        list(
                          extend = 'csv',
                          filename = paste0("HAT-Restoration-Site-Invasives-Yearly-Data-", Sys.Date())
                        ),
                        list(
                          extend = 'excel',
                          filename = paste0("HAT-Restoration-Site-Invasives-Yearly-Data-", Sys.Date())
                        ),
                        list(
                          extend = 'print',
                          title = 'HAT Restoration Invasives Yearly Site Data' # Change title here
                        )
                          ),
                        # removed previous / next buttons
                         paging = FALSE, 
                    # centre contents of columns 4,5 8
                         columnDefs = list(list(className = 'dt-center', targets = c(1,3:5))
                            )
           ))
```


Cover Mean
=====================================  

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

```{r filter-input-cover}
#############################################
htmltools::br()
htmltools::br()

#############################################
h4("Filtered Statistics")
p(class = "container", class = "value", summarywidget(sd_cover, column = "mean_value", statistic = "sum", digits = 2), span(class = "caption", "= mean % cover"))
htmltools::br()
htmltools::hr(style = "border: 0.5px solid grey; width: 250px; margin: auto;")

#############################################
# Create a filter input
h4("Filters")
filter_checkbox(id = "Site", label = "Choose Site", sharedData = sd_cover, group = ~ Site, allLevels = TRUE)
filter_checkbox(id = "Year", label = "Choose Year", sharedData = sd_cover, group = ~ Year, allLevels = TRUE)
filter_checkbox(id = "Treated", label = "Choose Treatment", sharedData = sd_cover, group = ~ Treated, allLevels = TRUE)
filter_select(id = "Species", label = "Choose Species", sharedData = sd_cover, group = ~ Species, multiple = TRUE)
htmltools::br()

#############################################
htmltools::HTML("<strong>Data Source:</strong> <em>Cover Data 2024-2025</em>")
htmltools::br()
htmltools::br()
htmltools::hr(style = "border: 0.5px solid grey; width: 250px; margin: auto;")
htmltools::br()
# HTML("<img src='https://images.squarespace-cdn.com/content/v1/5e3c5b7e5460c55405a6d4d6/a8c2fb30-96fd-4042-925f-e76c7040dce6/Black+Logo+2.png?format=5w'>")
HTML("<img src='images/HAT-logo-ss.png', width = 100>")
htmltools::br()
htmltools::br()
```

Row  {data-height=75}
-----------------------------------------------

### ***Mean % Species Cover Data***
```{r}
htmltools::HTML("
  Cover data was collected using quadrat-sampling methods at Matson in July 2024 and 2025, and at Oak Haven, in both treated and untreated sample plots, during April 2024 and 2025. As different seasonal meadows species were sampled, the comparison data between sites may not be as meaningful as if sampled during the same season in different years.")
```


Row {.tabset .tabset-fade}
---------------------------------------------

### Native Species (bar)
```{r mean-cover-nat, echo = FALSE, message = FALSE, warning = FALSE}
#############################################
custom_colours_years <- c("2022" = "#ffff33", 
                    "2023" = "#4daf4a", 
                    "2024" = "#984ea3", 
                    "2025" = "#ff7f00")
# custom_colours_Site_2 <- c("Matson" = "#f8766d", 
#                     "Oak Haven" = "#619cff")

#############################################
ggplotly(
  ggplot(sd_cover_nat, aes(x = reorder(Species, desc(Species)), y = mean_value, fill = as.factor(Year), 
                                                          text = paste("Year:", Year,
                                                          "\nSite:", Site,
                                                          "\nSpecies:", Species,      
                                                          "\nNative or Invasive:", Native_or_Invasive,  
                                                          "\nTreated:", Treated,
                                                          "\nMean Value:", mean_value,
                                                          "\nSD Value:", sd_value,
                                                          "\nUpper Mean Range:", upper,
                                                          "\nLower Mean Range:", lower))) + 
  geom_bar(stat = "identity", width = 0.5, position = position_dodge(0.7)) +
  #facet_wrap(vars(Site)) +
  facet_grid(Treated ~ Site) +
  coord_flip() + 
  theme_minimal() + #get rid of grey background and tick marks
  theme(legend.position ="bottom") + 
    scale_fill_manual(values = custom_colours_years) +
    # scale_fill_manual(values = custom_colours_Site_2) +
  theme(strip.background = element_rect(color = "black", fill = "#b5c0c1", size = 0.5, linetype = "solid"),
        strip.text = element_text(size = 11)) + 
      labs(
          title = "Native Species Mean % Cover at Matson & Oak Haven by Treatment", 
          x = "",   
          y = "Mean % cover",   
          fill = ""
          ) +
  theme(axis.text.x = element_text(angle = 0, vjust = 1, hjust=1, size = 7)) +
    # aligns title to left
  theme(plot.title = element_text(hjust = 0)) , 
  
  tooltip = "text",
  config = (displayModeBar = False) 
  ) %>%
    layout(legend = list(orientation = "h",
    xanchor="center",
    #x = 0.5 legend too close to x axis label
    # x = 1 # too far to right
    x = 0.5,
    # gives some space between x axis label and legend
    y = -0.2
    ))
```

### Native Species (points with error)
```{r mean-cover-nat-nancy, echo = FALSE, message = FALSE, warning = FALSE}
#############################################
# custom_colours_years <- c("2022" = "#ffff33", 
#                     "2023" = "#4daf4a", 
#                     "2024" = "#984ea3", 
#                     "2025" = "#ff7f00")

#############################################
custom_colours_treat <- c("Untreated" = "#d8b365", 
                    "Treated" = "#5ab4ac")
# custom_colours_Site_2 <- c("Matson" = "#f8766d", 
#                     "Oak Haven" = "#619cff")

#############################################
ggplotly(
  ggplot(sd_cover_nat, aes(x = reorder(Species, desc(Species)), y = mean_value,  fill = Treated, 
                                                          text = paste("Year:", Year,
                                                          "\nSite:", Site,
                                                          "\nSpecies:", Species,      
                                                          "\nNative or Invasive:", Native_or_Invasive,  
                                                          "\nTreated:", Treated,
                                                          "\nMean Value:", mean_value,
                                                          "\nSD Value:", sd_value,
                                                          "\nUpper Mean Range:", upper,
                                                          "\nLower Mean Range:", lower))) + 
  geom_point(size = 3, alpha = 0.75) +
  geom_errorbar(aes(ymin = lower, ymax = upper)) +
  coord_cartesian(ylim = c(0, NA)) + # This zooms the y-axis starting at 0, keeping all data  
  #facet_wrap(vars(Site)) +
  facet_grid(Year ~ Site) +
  coord_flip() + 
  theme_minimal() + #get rid of grey background and tick marks
  theme(legend.position ="bottom") + 
    scale_fill_manual(values = custom_colours_treat) +
    # scale_fill_manual(values = custom_colours_Site_2) +
  theme(strip.background = element_rect(color = "black", fill = "#b5c0c1", size = 0.5, linetype = "solid"),
        strip.text = element_text(size = 11)) + 
      labs(
          title = "Native Species Mean % Cover at Matson & Oak Haven by Treatment", 
          x = "",   
          y = "Mean % cover",   
          fill = ""
          ) +
  theme(axis.text.x = element_text(angle = 0, vjust = 1, hjust=1, size = 7)) +
    # aligns title to left
  theme(plot.title = element_text(hjust = 0)) , 
  
  tooltip = "text",
  config = (displayModeBar = False) 
  ) %>%
    layout(legend = list(orientation = "h",
    xanchor="center",
    #x = 0.5 legend too close to x axis label
    # x = 1 # too far to right
    x = 0.5,
    # gives some space between x axis label and legend
    y = -0.2
    ))
```




### Invasive Species
```{r mean-cover-inv, echo = FALSE, message = FALSE, warning = FALSE}
#############################################
# create custom colour-blind-friendly palette
custom_colours_years <- c("2022" = "#ffff33", 
                    "2023" = "#4daf4a", 
                    "2024" = "#984ea3", 
                    "2025" = "#ff7f00")
# custom_colours_Site_2 <- c("Matson" = "#f8766d", 
#                     "Oak Haven" = "#619cff")

#############################################
ggplotly(
  ggplot(sd_cover_inv, aes(x = reorder(Species, desc(Species)), y = mean_value, fill = as.factor(Year), 
                                                          text = paste("Year:", Year,
                                                          "\nSite:", Site,
                                                          "\nSpecies:", Species,      
                                                          "\nNative or Invasive:", Native_or_Invasive,  
                                                          "\nTreated:", Treated,
                                                          "\nMean Value:", mean_value,
                                                          "\nSD Value:", sd_value,
                                                          "\nUpper Mean Range:", upper,
                                                          "\nLower Mean Range:", lower))) + 
  geom_bar(stat = "identity", width = 0.5, position = position_dodge(0.7)) +
  #facet_wrap(vars(Site)) +
  facet_grid(Treated ~ Site) +
  coord_flip() +     
  theme_minimal() + #get rid of grey background and tick marks
  theme(legend.position ="bottom") + 
    scale_fill_manual(values = custom_colours_years) +
    #scale_fill_manual(values = custom_colours_Site_2) +
  theme(strip.background = element_rect(color = "black", fill = "#b5c0c1", size = 0.5, linetype = "solid"),
        strip.text = element_text(size = 11)) +
  labs(
        title = "Invasive Species Mean % Cover at Matson & Oak Haven by Treatment",        
        x = "",  
        y = "Mean % cover", 
        fill = ""
      ) +
  theme(axis.text.x = element_text(angle = 0, vjust = 1, hjust=1, size = 7)) +
      # aligns title to left
  theme(plot.title = element_text(hjust = 0)), 
  tooltip = "text",
  config = (displayModeBar = False) 
  ) %>%
    layout(legend = list(orientation = "h",
    xanchor="center",
    #x = 0.5 legend too close to x axis label
    x = 0.5,
    # gives some space between x axis label and legend
    y = -0.2
    ))
```

### Mixed Grasses
```{r mean-cover-grs, echo = FALSE, message = FALSE, warning = FALSE}
#############################################
custom_colours_years <- c("2022" = "#ffff33", 
                    "2023" = "#4daf4a", 
                    "2024" = "#984ea3", 
                    "2025" = "#ff7f00")
# custom_colours_Site_2 <- c("Matson" = "#f8766d", 
#                     "Oak Haven" = "#619cff")

#############################################
ggplotly(
  ggplot(sd_cover_grs, aes(x = reorder(Species, desc(Species)), y = mean_value, fill = as.factor(Year), 
                                                          text = paste("Year:", Year,
                                                          "\nSite:", Site,
                                                          "\nSpecies:", Species,      
                                                          "\nNative or Invasive:", Native_or_Invasive,  
                                                          "\nTreated:", Treated,
                                                          "\nMean Value:", mean_value,
                                                          "\nSD Value:", sd_value,
                                                          "\nUpper Mean Range:", upper,
                                                          "\nLower Mean Range:", lower))) + 
  geom_bar(stat = "identity", width = 0.5, position = position_dodge(0.7)) +
  # facet_wrap(vars(Site)) +
  facet_grid(Treated ~ Site) +
  coord_flip() + 
  theme_minimal() + #get rid of grey background and tick marks
  theme(legend.position ="bottom") + 
    scale_fill_manual(values = custom_colours_years) +
    #scale_fill_manual(values = custom_colours_Site_2) +
  theme(strip.background = element_rect(color = "black", fill = "#b5c0c1", size = 0.5, linetype = "solid"),
        strip.text = element_text(size = 11)) +
  labs(
        title = "Mixed Grasses Mean % Cover at Matson & Oak Haven by Treatment",     
        x = "",   
        y = "Mean % cover",
        fill = ""
        ) +
  theme(axis.text.x = element_text(angle = 0, vjust = 1, hjust=1, size = 7)) + 
      # aligns title to left
  theme(plot.title = element_text(hjust = 0)), 
  tooltip = "text",
  config = (displayModeBar = False) 
  ) %>%
    layout(legend = list(orientation = "h",
    xanchor="center",
    #x = 0.5 legend too close to x axis label
    x = 0.5,
    # gives some space between x axis label and legend
    y = -0.2
    ))
```

### Datatable
```{r data-table-cover}
htmltools::h5("Mean Cover (Native/Invasive & Treated/Untreated) Datatable")
htmltools::br()
 datatable(sd_cover, rownames = FALSE, class = 'compact',
           extensions = c("Buttons"),
           options = list(dom = 'Bfrtip',
                         buttons = list(                        
                        'colvis',
                        list(
                          extend = 'csv',
                          filename = paste0("HAT-Restoration-Site-Cover-Mean-Data-", Sys.Date())
                        ),
                        list(
                          extend = 'excel',
                          filename = paste0("HAT-Restoration-Site-Cover-Mean-Data-", Sys.Date())
                        ),
                        list(
                          extend = 'print',
                          title = 'HAT Restoration Mean Cover Data' # Change title here
                        )
                          ),
                        # removed previous / next buttons
                         paging = FALSE,                         
             columnDefs = list(list(className = 'dt-center', targets = c(0,6,7))
           )))
```


Top 5 Cover
=====================================  

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

```{r filter-input-cover-top5}
#############################################
htmltools::br()
htmltools::br()

#############################################
h4("Filtered Statistics")
p(class = "container", class = "value", summarywidget(sd_cover, column = "mean_value", statistic = "sum", digits = 2), span(class = "caption", "= mean % cover"))
htmltools::br()
htmltools::hr(style = "border: 0.5px solid grey; width: 250px; margin: auto;")

#############################################
# Create a filter input
h4("Filters")
filter_checkbox(id = "Site", label = "Choose Site", sharedData = sd_cov_nat_top5, group = ~ Site, allLevels = TRUE)
filter_checkbox(id = "Year", label = "Choose Year", sharedData = sd_cov_nat_top5, group = ~ Year, allLevels = TRUE)
filter_checkbox(id = "Treated", label = "Choose Treatment", sharedData = sd_cov_nat_top5, group = ~ Treated, allLevels = TRUE)
filter_select(id = "Species", label = "Choose Species", sharedData = sd_cov_nat_top5, group = ~ Species, multiple = TRUE)
htmltools::br()

#############################################
htmltools::HTML("<strong>Data Source:</strong> <em>Cover Data 2024-2025</em>")
htmltools::br()
htmltools::br()
htmltools::hr(style = "border: 0.5px solid grey; width: 250px; margin: auto;")
htmltools::br()
# HTML("<img src='https://images.squarespace-cdn.com/content/v1/5e3c5b7e5460c55405a6d4d6/a8c2fb30-96fd-4042-925f-e76c7040dce6/Black+Logo+2.png?format=5w'>")
HTML("<img src='images/HAT-logo-ss.png', width = 100>")
htmltools::br()
htmltools::br()
```

Row  {data-height=25}
-----------------------------------------------

### ***Mean % Top 5 Native Species Cover Data***
```{r}
htmltools::HTML("
Mean cover data is subset to view only top 5 Native Species. Error bars show the upper and lower ranges of the standard deviation from mean values.")
```


Row {.tabset .tabset-fade}
-----------------------------------------------


### Top 5 Native Species Site~Year (Error bar)
```{r mean-cover-nat-nancy-top5-site-year, echo = FALSE, message = FALSE, warning = FALSE}
#############################################
# custom_colours_years <- c("2022" = "#ffff33", 
#                     "2023" = "#4daf4a", 
#                     "2024" = "#984ea3", 
#                     "2025" = "#ff7f00")

#############################################
custom_colours_treat <- c("Untreated" = "#d8b365", 
                    "Treated" = "#5ab4ac")
# custom_colours_Site_2 <- c("Matson" = "#f8766d", 
#                     "Oak Haven" = "#619cff")

#############################################
ggplotly(
  ggplot(sd_cov_nat_top5, aes(x = reorder(Species, desc(Species)), y = mean_value,  fill = Treated, 
                                                          text = paste("Year:", Year,
                                                          "\nSite:", Site,
                                                          "\nSpecies:", Species,      
                                                          "\nNative or Invasive:", Native_or_Invasive,  
                                                          "\nTreated:", Treated,
                                                          "\nMean Value:", mean_value,
                                                          "\nSD Value:", sd_value,
                                                          "\nUpper Mean Range:", upper,
                                                          "\nLower Mean Range:", lower))) + 
  # geom_bar(stat = "identity", width = 0.5, position = position_dodge(0.7)) +
  geom_point(size = 3, alpha = 0.75) +
    
  geom_errorbar(aes(ymin = lower, ymax = upper)) +
  coord_cartesian(ylim = c(0, NA)) + # This zooms the y-axis starting at 0, keeping all data  
  #facet_wrap(vars(Site)) +
  facet_grid(Site ~ Year) +
  coord_flip() + 
  theme_minimal() + #get rid of grey background and tick marks
  theme(legend.position ="bottom") + 
    scale_fill_manual(values = custom_colours_treat) +
    # scale_fill_manual(values = custom_colours_Site_2) +
  theme(strip.background = element_rect(color = "black", fill = "#b5c0c1", size = 0.5, linetype = "solid"),
        strip.text = element_text(size = 11)) + 
      labs(
          title = "Native Species Mean % Cover at Matson & Oak Haven by Treatment", 
          x = "",   
          y = "Mean % cover",   
          fill = ""
          ) +
  theme(axis.text.x = element_text(angle = 0, vjust = 1, hjust=1, size = 7)) +
    # aligns title to left
  theme(plot.title = element_text(hjust = 0)) , 
  
  tooltip = "text",
  config = (displayModeBar = False) 
  ) %>%
    layout(legend = list(orientation = "h",
    xanchor="center",
    #x = 0.5 legend too close to x axis label
    # x = 1 # too far to right
    x = 0.5,
    # gives some space between x axis label and legend
    y = -0.2
    ))
```



```{r mean-cover-nat-nancy-top5-year-site, echo = FALSE, message = FALSE, warning = FALSE}
# ### Top 5 Native Nancy's Native Species Year ~ Site
# #############################################
# # custom_colours_years <- c("2022" = "#ffff33", 
# #                     "2023" = "#4daf4a", 
# #                     "2024" = "#984ea3", 
# #                     "2025" = "#ff7f00")
# 
# #############################################
# custom_colours_treat <- c("Untreated" = "#d8b365", 
#                     "Treated" = "#5ab4ac")
# # custom_colours_Site_2 <- c("Matson" = "#f8766d", 
# #                     "Oak Haven" = "#619cff")
# 
# #############################################
# ggplotly(
#   ggplot(sd_cov_nat_top5, aes(x = reorder(Species, desc(Species)), y = mean_value,  fill = Treated, 
#                                                           text = paste("Year:", Year,
#                                                           "\nSite:", Site,
#                                                           "\nSpecies:", Species,      
#                                                           "\nNative or Invasive:", Native_or_Invasive,  
#                                                           "\nTreated:", Treated,
#                                                           "\nMean Value:", mean_value,
#                                                           "\nSD Value:", sd_value))) + 
#   # geom_bar(stat = "identity", width = 0.5, position = position_dodge(0.7)) +
#   geom_point(size = 3, alpha = 0.75) +
#     
#   geom_errorbar(aes(ymin = lower, ymax = upper)) +
#   coord_cartesian(ylim = c(0, NA)) + # This zooms the y-axis starting at 0, keeping all data  
#   #facet_wrap(vars(Site)) +
#   facet_grid(Year ~ Site) +
#   coord_flip() + 
#   theme_minimal() + #get rid of grey background and tick marks
#   theme(legend.position ="bottom") + 
#     scale_fill_manual(values = custom_colours_treat) +
#     # scale_fill_manual(values = custom_colours_Site_2) +
#   theme(strip.background = element_rect(color = "black", fill = "#b5c0c1", size = 0.5, linetype = "solid"),
#         strip.text = element_text(size = 11)) + 
#       labs(
#           title = "Native Species Mean % Cover at Matson & Oak Haven by Treatment", 
#           x = "",   
#           y = "Mean % cover",   
#           fill = ""
#           ) +
#   theme(axis.text.x = element_text(angle = 0, vjust = 1, hjust=1, size = 7)) +
#     # aligns title to left
#   theme(plot.title = element_text(hjust = 0)) , 
#   
#   tooltip = "text",
#   config = (displayModeBar = False) 
#   ) %>%
#     layout(legend = list(orientation = "h",
#     xanchor="center",
#     #x = 0.5 legend too close to x axis label
#     # x = 1 # too far to right
#     x = 0.5,
#     # gives some space between x axis label and legend
#     y = -0.2
#     ))
```

### Datatable
```{r data-table-cover-top5}
htmltools::h5("Top 5 Mean Cover (Native/Invasive & Treated/Untreated) Datatable")
htmltools::br()
 datatable(sd_cov_nat_top5, rownames = FALSE, class = 'compact',
           extensions = c("Buttons"),
           options = list(dom = 'Bfrtip',
                         buttons = list(                        
                        'colvis',
                        list(
                          extend = 'csv',
                          filename = paste0("HAT-Restoration-Site-Top5-Cover-Mean-Data-", Sys.Date())
                        ),
                        list(
                          extend = 'excel',
                          filename = paste0("HAT-Restoration-Site-Top5-Cover-Mean-Data-", Sys.Date())
                        ),
                        list(
                          extend = 'print',
                          title = 'HAT Restoration Mean Top 5 Cover Data' # Change title here
                        )
                          ),
                        # removed previous / next buttons
                         paging = FALSE,                         
             columnDefs = list(list(className = 'dt-center', targets = c(0,6,7))
           )))
```

Species Richness
=====================================  

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

```{r filter-input-count}
#############################################
htmltools::br()
htmltools::br()
h4("Filtered Statistics")
p(class = "container", class = "value", summarywidget(sd_count, column = "Species_number", statistic = "sum"), span(class = "caption", "= different species", digits = 2))
htmltools::br()
htmltools::hr(style = "border: 0.5px solid grey; width: 250px; margin: auto;")

#############################################
# Create a filter input
h4("Filters")
filter_checkbox(id = "Site", label = "Choose Site", sharedData = sd_count, group = ~ Site, allLevels = TRUE)
filter_checkbox(id = "Year", label = "Choose Year", sharedData = sd_count, group = ~ Year, allLevels = TRUE)
filter_checkbox(id = "Treated", label = "Choose Treatment", sharedData = sd_count, group = ~ Treated, allLevels = TRUE)
filter_checkbox(id = "Native_or_Invasive", label = "Choose Native or Invasive", sharedData = sd_count, group = ~ Native_or_Invasive, allLevels = TRUE)

#############################################
htmltools::br()
htmltools::HTML("<strong>Data Source:</strong> <em>Cover Data 2024-2025</em>")
htmltools::br()
htmltools::br()
htmltools::hr(style = "border: 0.5px solid grey; width: 250px; margin: auto;")
htmltools::br()
# HTML("<img src='https://images.squarespace-cdn.com/content/v1/5e3c5b7e5460c55405a6d4d6/a8c2fb30-96fd-4042-925f-e76c7040dce6/Black+Logo+2.png?format=5w'>")
HTML("<img src='images/HAT-logo-ss.png', width = 100>")
htmltools::br()
htmltools::br()
```

Row  {data-height=140}
-----------------------------------------------

### ***Species Richness Unique Count @ Matson & Oak Haven***
```{r}
htmltools::HTML("
  Mean % cover data was collected using quadrat-sampling methods July 2024 and 2025 at Matson, and April 2024 and 2025 at Oak Haven. Species Richness counts each unique species found. When meadows species were sampled during different seasons, any meaningful comparison between sites may be affected. <strong>Example Analysis: </strong> Invasive species count is higher in treated areas ... Does invasive species removal create an environment for more invasive species to move in?")
```


Row {.tabset .tabset-fade}
---------------------------------------------

### **Species Counts by Year & Site** 
```{r species-richness-count-facet-site}
#############################################
# create custom colour-blind-friendly palette
custom_colours_3 <- c("Invasive" = "#fc8d62", 
                    "Native" = "#66c2a5", 
                    "MixedGrass" = "#8da0cb")

#############################################
ggplotly(
  ggplot(sd_count, aes(x = Treated, y = Species_number, fill = Native_or_Invasive, 
         text = paste("Year:", Year,
                      "\nSite:", Site,
                      "\nTreated:", Treated,
                      "\nNative or Invasive", Native_or_Invasive,
                      "\nSpecies Number", Species_number))) + 
  geom_bar(stat = "identity", width = 0.5, position = position_dodge(0.7)) +
  # geom_text(aes(label = Year), 
  #            position = position_dodge(),
  #            hjust = -0.5, vjust = -0.5, size = 2, 
  #            fontface = "bold") +
  # facet_wrap( ~ Site) +
  facet_grid(Site ~ Year) +  
  theme_minimal() + #get rid of grey background and tick marks
  theme(strip.background = element_rect(color = "black", fill = "#b5c0c1", size = 0.5, linetype = "solid"),
        strip.text = element_text(size = 11)) +
  theme(legend.position ="bottom") + 
  theme(axis.text.x = element_text(angle = 0, vjust = 1, hjust=1, size = 7)) +
          # aligns title to left
  theme(plot.title = element_text(hjust = 0)) +
  scale_fill_manual(values = custom_colours_3) +
  labs(
      title='Species Richness Count at Matson and Oak Haven',
      fill = "",
      x = "Treatment", 
      y = "Species Count") +
  theme(axis.text.x = element_text(angle = 0, vjust = 1, hjust=1, size = 7)), 
  tooltip = "text",
  config = (displayModeBar = False) 
  ) %>%
    layout(legend = list(orientation = "h",
    xanchor="center",
    x = 0.5,
    # gives some space between x axis label and legend
    y = -0.2
    ))
```


```{r species-richness-count}
# ### **Species Counts** 
#############################################
# # create custom colour-blind-friendly palette
# custom_colours_3 <- c("Invasive" = "#fc8d62", 
#                     "Native" = "#66c2a5", 
#                     "MixedGrass" = "#8da0cb")
#
#############################################
# ggplotly(
#   ggplot(sd_count, aes(x = Treated, y = Species_number, fill = Native_or_Invasive, 
#          text = paste("Year:", Year,
#                       "\nSite:", Site,
#                       "\nTreated:", Treated,
#                       "\nNative or Invasive", Native_or_Invasive,
#                       "\nSpecies Number", Species_number))) + 
#   geom_bar(stat = "identity", width = 0.5, position = "dodge") +
#   theme_minimal() + #get rid of grey background and tick marks
#   theme(legend.position ="bottom") + 
#   theme(axis.text.x = element_text(angle = 0, vjust = 1, hjust=1, size = 7)) +
#           # aligns title to left
#   theme(plot.title = element_text(hjust = 0)) +
#   scale_fill_manual(values = custom_colours_3) +
#   labs(
#       title='Count of unique species at Oak Haven and Matson',
#       fill = "",
#       x = "Treatment", 
#       y = "Species Count") +
#   theme(axis.text.x = element_text(angle = 0, vjust = 1, hjust=1, size = 7)), 
#   tooltip = "text",
#   config = (displayModeBar = False) 
#   ) %>%
#     layout(legend = list(orientation = "h",
#     xanchor="center",
#     x = 0.5,
#     # gives some space between x axis label and legend
#     y = -0.2
#     ))
```


```{r species-richness-count-facet-yr}
### **Species Counts by Year** 
#############################################
# create custom colour-blind-friendly palette
# custom_colours_3 <- c("Invasive" = "#fc8d62", 
#                     "Native" = "#66c2a5", 
#                     "MixedGrass" = "#8da0cb")
#
#############################################
# ggplotly(
#   ggplot(sd_count, aes(x = Treated, y = Species_number, fill = Native_or_Invasive, 
#          text = paste("Year:", Year,
#                       "\nSite:", Site,
#                       "\nTreated:", Treated,
#                       "\nNative or Invasive", Native_or_Invasive,
#                       "\nSpecies Number", Species_number))) + 
#   geom_bar(stat = "identity", width = 0.5, position = "dodge") +
#   facet_wrap( ~ Year) +
# 
#   theme_minimal() + #get rid of grey background and tick marks
#   theme(strip.background = element_rect(color = "black", fill = "#b5c0c1", size = 0.5, linetype = "solid"),
#         strip.text = element_text(size = 11)) +
#   theme(legend.position ="bottom") + 
#   theme(axis.text.x = element_text(angle = 0, vjust = 1, hjust=1, size = 7)) +
#           # aligns title to left
#   theme(plot.title = element_text(hjust = 0)) +
#   scale_fill_manual(values = custom_colours_3) +
#   labs(
#       title='Count of unique species at Oak Haven and Matson by year',
#       fill = "",
#       x = "Treatment", 
#       y = "Species Count") +
#   theme(axis.text.x = element_text(angle = 0, vjust = 1, hjust=1, size = 7)), 
#   tooltip = "text",
#   config = (displayModeBar = False) 
#   ) %>%
#     layout(legend = list(orientation = "h",
#     xanchor="center",
#     x = 0.5,
#     # gives some space between x axis label and legend
#     y = -0.2
#     ))
```


### Datatable
```{r data-table-count}
htmltools::h5("Species Count Datatable")
htmltools::br()
 datatable(sd_count, rownames = FALSE, class = 'compact',
           extensions = c("Buttons"),
           options = list(dom = 'Bfrtip',
                         buttons = list(                        
                        'colvis',
                        list(
                          extend = 'csv',
                          filename = paste0("HAT-Restoration-Site-Species-Count-Data-", Sys.Date())
                        ),
                        list(
                          extend = 'excel',
                          filename = paste0("HAT-Restoration-Site-Species-Count-Data-", Sys.Date())
                        ),
                        list(
                          extend = 'print',
                          title = 'HAT Restoration Species Count Data' # Change title here
                        )
                          ),
                        # removed previous / next buttons
                         paging = FALSE,                         
             columnDefs = list(list(className = 'dt-center', targets = c(0,4)
           ))))
```


 Map
=====================================  

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

```{r filter-input-map}
#############################################
htmltools::br()
htmltools::br()
HTML("<img src='images/HAT-logo-ss.png', width=150>")
htmltools::br()
htmltools::br()

#############################################
h4("Filter")
htmltools::em("Note: To reset filters, delete unwanted choices")
htmltools::br()
htmltools::br()
# filter_checkbox(id = "Site", label = "Site", sharedData = sd_sites, group = ~Site)
filter_select(id = "Site", label = "Site", sharedData = sd_sites, group = ~Site)
filter_checkbox(id = "Top_5_Invasives", label = "Top 5 Invasives", sharedData = sd_sites, group = ~Top_5_Invasives)
filter_select(id = "Municipality", label = "Municipality", sharedData = sd_sites, group = ~Municipality)

#############################################
# HTML("<img src='https://images.squarespace-cdn.com/content/v1/5e3c5b7e5460c55405a6d4d6/a8c2fb30-96fd-4042-925f-e76c7040dce6/Black+Logo+2.png?format=5w'>")
# HTML("<img src='images/HAT-logo-ss.png', width = 100>")
htmltools::br()
htmltools::br()
htmltools::hr(style = "border: 0.5px solid grey; width: 250px; margin: auto;")
htmltools::br()
htmltools::em("HAT data source: ")
htmltools::a(href = "https://hat.bc.ca/community-based-restoration", "https://hat.bc.ca/community-based-restoration")
htmltools::br()
```

Row  {data-height=50}
-----------------------------------------------

### ***Interactive Map of 3 HAT Managed Public GOE Sites***
```{r}
htmltools::HTML("
3 public HAT sites listed on <a href='https://hat.bc.ca/community-based-restoration'>HAT's webpage</a>, all other sites are on private, non-public land with location protected for privacy. Click map markers to open pop-up windows site-specific information.
                ")
```

Row {.tabset .tabset-fade}
---------------------------------------------

### Interactive Map
```{r leaflet-all-sites, echo = FALSE, message = FALSE, include = TRUE}
#############################################
# title <- '<p style="text-align: center; height: 18px; "><img src="https://images.squarespace-cdn.com/content/v1/5e3c5b7e5460c55405a6d4d6/a8c2fb30-96fd-4042-925f-e76c7040dce6/Black+Logo+2.png?format=5w"><span style="font-size:9px;font-weight:bold; background-color: rgba(255, 255, 255, 0.9;");>GOE Monitoring Covenant Sites Map</span></p>'

title <- '<p style="text-align: center;"><span style="font-size:14px;font-weight:bold; background-color: rgba(255, 255, 255, 0.9;");>HAT GOE Monitoring Covenant Sites Map</span></p>'
     
          pal <- colorFactor(c("#1b9e77", "#7570b3", "#e7298a"), domain = c("Havenwood", "Matson", "Oak Haven"))

#############################################        
leaflet(sd_sites) %>%
      addProviderTiles("Esri.WorldImagery") %>%
      addCircleMarkers(
        ~ Lng, ~ Lat,
        color = ~pal(Site),
        weight = 1, # size of circle border
        stroke = TRUE, fillOpacity = 1, #fillOpacity = 0.5
        radius = 6,
        popup = paste0(
#        "<img src = 'images/HAT-logo-ss.png', width = 100>",  "<br>","<br>",
#                "<img src = 'https://images.squarespace-cdn.com/content/v1/5e3c5b7e5460c55405a6d4d6/a8c2fb30-96fd-4042-925f-e76c7040dce6/Black+Logo+2.png?format=5w'>",  "<br>","<br>",
        # NOTE: popups need to refer to original data object, not shared sd
          "<b>Site:</b> ", "<b>", HAT_sites_HAT$Site, "</b>",  "<br>",
          "<b>FullName:</b> ", "<b>", HAT_sites_HAT$Site_Name, "</b>",  "<br>",
          "<b>Municipality:</b> ", HAT_sites_HAT$Municipality, "<br>",
          "<b>Size:</b> ", HAT_sites_HAT$Size_ha, " (ha)", "<br>",
          "<b>First Nations:</b> ", HAT_sites_HAT$FirstNations, "<br>",
          # "<b>Project id:</b> ", HAT_sites_HAT$ID, "<br>",
          "<b>HAT Status:</b> ", HAT_sites_HAT$HAT_Status, "<br>",
          "<b>Co-Covenant:</b> ", HAT_sites_HAT$Co_Covenant, " (", HAT_sites_HAT$Date, ")", "<br>",
          "<b>Ecosystems:</b> ", HAT_sites_HAT$Ecosystems, "<br>",
          "<b>Volunteer Stewardship:</b> ", HAT_sites_HAT$Volunteer_Stewardship, "<br><br>",
        "<b>Top 5 Invasives Species:</b> ", HAT_sites_HAT$Top_5_Invasives, "<br><br>",
        
#############################################        
    '<table style="border: 0px solid black; vertical-align: top; font-size: 85%;">',
      '<tr style="vertical-align: top;">
        <th>BIOMASS PULL</th>        
        <th align="right">2022</th>
        <th align="right">2023</th>
        <th align="right">2024</th>
        <th align="right">2025</th>        
      </tr>', 
    
    # Hours per Biomass (m3)
      '<tr style="vertical-align: top;">',
        '<td style="vertical-align: top;"><b>Hours/Biomass (m3):  </b></td>',
        '<td align="right">', HAT_sites_HAT$Hours_per_Biomass_2022, '</td>',
        '<td align="right">', HAT_sites_HAT$Hours_per_Biomass_2023, '</td>',
        '<td align="right">', HAT_sites_HAT$Hours_per_Biomass_2024, '</td>',
        '<td align="right">', HAT_sites_HAT$Hours_per_Biomass_2025, '</td>',
      '</tr>',
    
    # Staff Hours
      '<tr style="vertical-align: top;">',
        '<td style="vertical-align: top;"><b>Crew Hours:  </b></td>',
        '<td align="right">', HAT_sites_HAT$Crew_Hours_2022, '</td>',
        '<td align="right">', HAT_sites_HAT$Crew_Hours_2023, '</td>',
        '<td align="right">', HAT_sites_HAT$Crew_Hours_2024, '</td>',
        '<td align="right">', HAT_sites_HAT$Crew_Hours_2025, '</td>',
      '</tr>',
    
    #Biomass Removed (m3)
      '<tr style="vertical-align: top;">',
        '<td style="vertical-align: top;"><b>Biomass (m3):  </b></td>',
        '<td align="right">', HAT_sites_HAT$Biomass_2022, '</td>',
        '<td align="right">', HAT_sites_HAT$Biomass_2023, '</td>',
        '<td align="right">', HAT_sites_HAT$Biomass_2024, '</td>',
        '<td align="right">', HAT_sites_HAT$Biomass_2025, '</td>',
      '</tr>',
    
        #Area of Biomass Removed (m3)
      '<tr style="vertical-align: top;">',
        '<td style="vertical-align: top;"><b>Area (m2):  </b></td>',
        '<td align="right">', HAT_sites_HAT$Area_2022, '</td>',
        '<td align="right">', HAT_sites_HAT$Area_2023, '</td>',
        '<td align="right">', HAT_sites_HAT$Area_2024, '</td>',
        '<td align="right">', HAT_sites_HAT$Area_2025, '</td>',
      '</tr>',
    '</table>'

#############################################
          ))  %>%
      addLegend("bottomright", pal = pal, values = HAT_sites_HAT$Site, title = "Site") %>%

      setView(-123.44799, 48.52919, 10) %>%
      # add controls
      #  addMiniMap(width = 150, height = 150, zoomLevelOffset = -4) %>%
      addControl(title, position = "topright")
```

### Datatable
```{r data-table-map}
htmltools::h5("HAT Public Sites Datatable")
htmltools::br()
 datatable(sd_sites, rownames = FALSE, class = 'compact',
           extensions = c("Buttons"),
           options = list(dom = 'Bfrtip',
                         buttons = list(                        
                        'colvis',
                        list(
                          extend = 'csv',
                          filename = paste0("HAT-Restoration-Site-Data-", Sys.Date())
                        ),
                        list(
                          extend = 'excel',
                          filename = paste0("HAT-Restoration-Site-Data-", Sys.Date())
                        ),
                        list(
                          extend = 'print',
                          title = 'HAT Restoration Site Data' # Change title here
                        )
                          ),
                        # removed previous / next buttons
                         paging = FALSE,                         
             columnDefs = list(list(className = 'dt-center', targets = c(0,6,7))
           )))
```

```{r session-info}
# Session Info to document specific packages used to run this script at a specific point in time
#############################################
sessionInfo()
```

<!-- Default Statcounter code for HAT Monitoring Dataviz
Project
https://wendyanthony.github.io/HAT/HAT-DataViz-webfilter.html
-->
<script type="text/javascript">
var sc_project=13198915; 
var sc_invisible=1; 
var sc_security="116553d3"; 
</script>
<script type="text/javascript"
src="https://www.statcounter.com/counter/counter.js"
async></script>
<noscript><div class="statcounter"><a title="free web stats"
href="https://statcounter.com/" target="_blank"><img
class="statcounter"
src="https://c.statcounter.com/13198915/0/116553d3/1/"
alt="free web stats"
referrerPolicy="no-referrer-when-downgrade"></a></div></noscript>
<!-- End of Statcounter Code -->