Map

Row

Interactive Maps of 3 HAT Managed Public GOE Sites

Click map markers to open pop-up windows for site information. Three public HAT sites are listed on HAT's webpage. Spatial data for Oak Haven includes restoration polygons and species locations, but does not respond to filters. Use layer menu toggle spatial data layers on/off. Measure distances with measuring tool. The geolocation map can toggle your location, after permission is given to browser to access location data. Added points are saved to console (right-click map > Inspect > Console > copy coordinates). Also a Stand-alone Webmap

Row

HAT 3-Sites Map

Oak Haven Spatial Data Geolocation Map

Datatable HAT 3-Sites

HAT Public Sites Datatable

Datatable OH Polygons

Oak Haven Polygons Datatable

Datatable OH Points

Oak Haven Points Datatable

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. 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: There is no volunteer data summarized

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 & 2025, and at Oak Haven in April 2024 & 2025, in treated and untreated plots. Site sampling GOM species during different seasons may not be as meaningful for comparison as sampling during the same seasons. Charts show the standard variation around the mean % cover.

Row

Native Species (mean value variation)

Invasive Species (mean value variation)

Mixed Grasses (mean value variation)

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 only top 5 Native Species. Error bars show 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

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
Click to close/open Crew Site Data details
* Metrics: Daily and Yearly crew hours and biomass (metres3) and area (metres2) of invasive species removed;
* 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 Volunteer Field Logs
Click open for Volunteer Field Logs details
* Metrics: Daily volunteer work hours and 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
Click open for Cover Data details
* Metrics: Cover Mean % (Native/Invasive & Treated/Untreated); Species Richness
* Sites: Matson, Oak Haven
* Datasets: Cover Data 2024-2025

4. Site Data
Click open for Site Data details
* Metrics: Location; 2022-2025; Top 5 Invasive Species Removed, crew hours, biomass removed, hours per m3;
* Sites: Havenwood, Matson, Oak Haven
* Data: https://hat.bc.ca/community-based-restoration

5. Spatial Data
Click open for Spatial Data details
* Metrics: 2023-2025 Invasive Species Removed; shiny geranium priorities; test plots
* Sites: Oak Haven
* Data: Polygons and Points Shape files

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
---
title: "Visualizing HAT Monitoring Data"
output: 
  flexdashboard::flex_dashboard:
    favicon: HAT-favicon-60.png
    orientation: rows
    vertical_layout: fill
    theme: 
      version: 4
      bootswatch: flatly
    source_code: embed
---
  
```{r readme, include=FALSE}
# HAT Interactive Data Visualization Dashboard Tool
# 
# Purpose: Interactive dashboard for visualizing GOE restoration monitoring data
# Data sources: 
#   - Site Data: data/HAT-Sites-HAT.csv
#   - Crew activities: data/crew_data_sep_sub.csv
#   - Volunteer data: data/
#   - Cover Data: data/HAT_cover_mean.csv
#   - Spatial features: data_spatial/*.shp
#
# Last updated: 2026-02-21
# Maintainer: Wendy Anthony wanthony@uvic.ca
```

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

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

```{css}

/* ************************************** */  
/* **** Flexbox css already has Media queries do I need these? ***** */  
/* **** Media queries screen size ***** */  

/* xs */
/* @media (min-width: 475px) {} */

/* sm */
/* @media (min-width: 640px) {} */

/* md */
/* @media (min-width: 768px) {} */

/* lg */
/* @media (min-width: 1024px) {} */

/* xl */
/* @media (min-width: 1280px) {} */

/* 2xl */
/* @media (min-width: 1536px) {} */
  
/* ************************************** */  
/* **** Navigation links font size ***** */  

/* Adjust font size for navbar links */
.navbar-nav a {
  font-size: 14px !important;
  /* Use font-size: 14px !important; - !important to ensure the style overrides existing ones */
}

/* Adjust font size of source code link */
.navbar-right a {
    font-size: 10px !important;
}  

  
/* ************************************** */  
/* **** Tab font colours ***** */  
  
/* 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;
}
*/
  
/* ************************************** */  
/* **** Sidebar padding ***** */  

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


/* ************************************** */  
/* **** navbar colours ***** */  

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

/* ************************************** */  
/* **** bold paragraph ***** */  

p {
  font-weight: bold;
}

/* ************************************** */  
/* **** contiainer ***** */  

.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;
}

/* ************************************** */  
/* **** Filter Stats Value ***** */  

.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;
}

/* ************************************** */  
/* **** Filter Stats Caption font size & colours ***** */  

.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 #
#############################################

# Load Core Package Libraries
#############################################
# install.packages("flexdashboard")
library(flexdashboard) # dashboard
# install.packages("crosstalk")
library(crosstalk) # shared data filters

# tool libraries
############################################# 
# install.packages("htmltools")
library(htmltools) # write HTML code in flexdashboard
# devtools::install_github("kent37/summarywidget")
library(summarywidget) # filtered data summary

# Load Data Wrangling and Visualization Package Libraries
#############################################
# 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

# Load Map & Spatial Data Package Libraries 
#############################################
# install.packages("leaflet")
library(leaflet) # interactive map
# install.packages("sf")
library(sf) # spatial data
# install.packages("leaflet.extras")
library(leaflet.extras) # for addControlGPS() & addDrawToolbar()
# install.packages("htmlwidgets")
library(htmlwidgets) # to save leaflet map as html & render js
```


```{r data-import-st-data-download, include = FALSE, cache = TRUE}
### Data preparation in file: HAT-DataViz-DataPrep-Spatial.Rmd
#############################################
## Import spatial Data
# str(OHP_2025_Experimental_test_plots_dropz)
OHP_2025_Experimental_test_plots_dropz <- st_read("data/data_spatial/OHP_2025_Experimental_test_plots_dropz/OHP_2025_Experimental_test_plots_dropz.shp")
OH_2024_Invasive_Species_Points_dropz <- st_read("data/data_spatial/OH_2024_Invasive_Species_Points_dropz/OH_2024_Invasive_Species_Points_dropz.shp")
OHP_2025_Completed_polygons_dropz <- st_read("data/data_spatial/OHP_2025_Completed_polygons_dropz/OHP_2025_Completed_polygons_dropz.shp")
OH_2024_Identified_Invasive_Species_Patches_dropz <- st_read("data/data_spatial/OH_2024_Identified_Invasive_Species_Patches_dropz/OH_2024_Identified_Invasive_Species_Patches_dropz.shp")
OH_2024_Invasive_Species_Removed_dropz <- st_read("data/data_spatial/OH_2024_Invasive_Species_Removed_dropz/OH_2024_Invasive_Species_Removed_dropz.shp")
OH_2024_ShinyG_Burning_Priorities_dropz <- st_read("data/data_spatial/OH_2024_ShinyG_Burning_Priorities_dropz/OH_2024_ShinyG_Burning_Priorities_dropz.shp")
```

```{r import-rbind-spatial-polygons-points, include = FALSE, cache = TRUE}
### Data preparation in file: HAT-DataViz-DataPrep-Spatial.Rmd
#############################################
## import Bind spatial polygons for Datatable Display
#str(OH_spatial_polygons_all_sub)
OH_spatial_polygons_all_sub <- read.csv("data/data_spatial/OH_spatial_polygons_all_sub_df.csv", fileEncoding="UTF-8")
#############################################
## import Bind spatial points for Datatable Display
OH_spatial_points_all_sub <- read.csv("data/data_spatial/OH_spatial_points_all_sub_df.csv", fileEncoding="UTF-8")
```



```{r import-wrangled-site-data-sd, include = FALSE}
# Sites Data
#############################################
# str(HAT_sites_HAT)
HAT_sites_HAT <- read.csv("data/HAT_sites_HAT_wrangled.csv", fileEncoding="UTF-8")
# str(HAT_sites_HAT)
#############################################
sd_sites <- SharedData$new(data = HAT_sites_HAT, group = "crew_group")### Create sharable database using Crosstalk packageå
```



```{r crew-shared-data, include = FALSE}
### Create sharable database using Crosstalk package
# Crew Data
#############################################

crew_vol <- read.csv("data/crew_vol.csv", fileEncoding="UTF-8")
# str(crew_vol)
# colnames(crew_vol)
crew_vol$Date <- as.Date(crew_vol$Date)
# 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")

crew_vol_inv <- read.csv("data/crew_vol_inv.csv", fileEncoding="UTF-8")
# str(crew_vol_inv)
# colnames(crew_vol_inv)
crew_vol_inv$Date <- as.Date(crew_vol_inv$Date)

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

#############################################
# Read Calculation subset

crew_vol_inv_top5 <- read.csv("data/crew_vol_inv_top5.csv", fileEncoding="UTF-8")
# str(crew_vol_inv_top5)
# colnames(crew_vol_inv_top5)
crew_vol_inv_top5$Date <- as.Date(crew_vol_inv_top5$Date)

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

#############################################
# Read Calculation subset
crew_vol_inv_top5_sum <- read.csv("data/crew_vol_inv_top5_sum.csv", fileEncoding="UTF-8")
# str(crew_vol_inv_top5_sum)

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

```{r crew-summary-data-sd, include = FALSE}
### Create sharable database using Crosstalk package
#############################################
# Summary data totals per year per site

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

# str(crew_data_sep_sub_sum_by_group_site_rename_site)
# used in Invasive Biomass charts
sd_crew <- SharedData$new(data = crew_data_sep_sub_sum_by_group_site_rename_site, group = "crew_group")
```


```{r cover-shared-data, include = FALSE}
# Import Cover Data
#############################################
cover_data_rename_site_sub <- read.csv("data/cover_data_rename_site_sub.csv", fileEncoding="UTF-8")
# str(cover_data_rename_site_sub)
cover_data_rename_site_sub$Date <- as.Date(cover_data_rename_site_sub$Date)

cover_data_rename_site_sub_grs <- read.csv("data/cover_data_rename_site_sub_grs.csv", fileEncoding="UTF-8")
# str(cover_data_rename_site_sub_grs)
#  colnames(cover_data_rename_site_sub_grs)
cover_data_rename_site_sub_grs$Date <- as.Date(cover_data_rename_site_sub_grs$Date)

cover_data_rename_site_sub_inv <- read.csv("data/cover_data_rename_site_sub_inv.csv", fileEncoding="UTF-8")
# str(cover_data_rename_site_sub_inv)
# colnames(cover_data_rename_site_sub_inv)
cover_data_rename_site_sub_inv$Date <- as.Date(cover_data_rename_site_sub_inv$Date)

cover_data_rename_site_sub_nat <- read.csv("data/cover_data_rename_site_sub_nat.csv", fileEncoding="UTF-8")
# str(cover_data_rename_site_sub_nat)
# colnames(cover_data_rename_site_sub_nat)
cover_data_rename_site_sub_nat$Date <- as.Date(cover_data_rename_site_sub_nat$Date)

cov_nat_top5 <- read.csv("data/cov_nat_top5.csv", fileEncoding="UTF-8")
# str(cov_nat_top5)
# colnames(cov_nat_top5)
cov_nat_top5$Date <- as.Date(cov_nat_top5$Date)

### Create sharable database using Crosstalk package
#############################################
# str(cov_nat_top5)
sd_cover <- SharedData$new(data = cover_data_rename_site_sub, 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_cov_nat_top5 <- SharedData$new(data = cov_nat_top5, group = "cover_group_top5")
```

```{r import-wrangled-species-count-data-sd, include = FALSE}
# Species Count Data
#############################################
species_count <- read.csv("data/species_count_wrangled.csv", fileEncoding="UTF-8")
str(species_count)
#############################################
sd_count <- SharedData$new(data = species_count, group = "count_group")
```




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

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

```{r filter-input-map}
#############################################
htmltools::br()
htmltools::br()
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: Interactive Tool for Visualizing HAT Monitoring Data")
hr(style = "border: 0.5px solid grey; width: 100%; margin: auto;")
br()
HTML("
Each navigation link in the top header hosts a page of different data visualization charts and datatables, uses a different dataset, and  responds to a different set of filters.
<br><br>")
hr(style = "border: 0.5px solid grey; width: 100%; margin: auto;")
hr(style = "border: 0.5px solid grey; width: 100%; margin: auto;")
br()
p("Filter for 3-Sites Map Only")
filter_select(id = "Site", label = "Choose Site for 3-Sites Map", sharedData = sd_sites, group = ~Site)
hr(style = "border: 0.5px solid grey; width: 100%; margin: auto;")
hr(style = "border: 0.5px solid grey; width: 100%; margin: auto;")
HTML("
<div style='font-size:80%; text-align:center;'>
<strong>Created and Coded for HAT <br>
by Wendy Anthony</strong><br>
wanthony@uvic.ca 
<br>
Modified: 2026-03-08 @ 20:20</div>
")
hr(style = "border: 0.5px solid grey; width: 100%; margin: auto;")
br()
```

Row  {data-height=115}
-----------------------------------------------

### ***Interactive Maps of 3 HAT Managed Public GOE Sites***
```{r}
htmltools::HTML("Click map markers to open pop-up windows for site information. 
Three public HAT sites are listed on <a href='https://hat.bc.ca/community-based-restoration'>HAT's webpage</a>. 
Spatial data for Oak Haven includes restoration polygons and species locations, but <em><strong>does not respond to filters</strong></em>.
Use layer menu toggle spatial data layers on/off. 
Measure distances with measuring tool.  
The geolocation map can toggle your location, after permission is given to browser to access location data. Added points are saved to console (right-click map > Inspect > Console > copy coordinates). Also a <a href='https://wendyanthony.github.io/HAT/WebMap/HAT_spatial_site_map_geoloc_draw.html' target='_blank'>Stand-alone Webmap</a>
")
```

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

### HAT 3-Sites Map 
```{r leaflet-both-sites-filter, echo = FALSE, message = FALSE, include = TRUE}
#############################################
title <- '<p style="text-align: center; height: 12px;"><span style="font-size:12px;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"))

#############################################        
map_all <- leaflet() %>%
      addProviderTiles("Esri.WorldImagery") %>%
      addCircleMarkers(
        data = sd_sites,
        ~ Lng, ~ Lat,
        color = ~pal(Site),
        weight = 1, # size of circle border
        stroke = TRUE, fillOpacity = 1, #fillOpacity = 0.5
        radius = 8,
        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>'

#############################################
          ))  %>%
  addPolygons(data = OHP_2025_Completed_polygons_dropz,
              group = "OH 2025 Completed polygons",
              color = "#AA4499", #AA4499 purple
              #fillColor = "purple",
              fillOpacity = 0.5,
              popup = paste0("<b>Name: </b>", OHP_2025_Completed_polygons_dropz$Name, "<br>",
                             "<b>Description: </b>", OHP_2025_Completed_polygons_dropz$PopupInfo)) %>%
  addCircleMarkers(data = OHP_2025_Experimental_test_plots_dropz,
              group = "OH 2025 Experimental test plot points",
              color = "#EECC66", #EECC66 light yellow
              #fillColor = "purple",
              fillOpacity = 0.8,
              weight = 1,
              radius = 3,
              popup = paste0("<b>Name: </b>", OHP_2025_Experimental_test_plots_dropz$Name, "<br>",
                            "<b>Description: </b>", OHP_2025_Experimental_test_plots_dropz$Descript, "<br>",
                            "<b>Date: </b>", OHP_2025_Experimental_test_plots_dropz$DateTimeS)) %>%
  addPolygons(data = OH_2024_ShinyG_Burning_Priorities_dropz,
              # covers same area as Invasive_Species_Patches
              group = "OH 2024 ShinyG Burning Priorities",
              # use a lighter colour so lighter Shiny will show over Species patches
              color = "#EE7733", #EE7733 orange
              #color = "blue",
              #fillColor = "blue",
              fillOpacity = 0.3,
              popup = paste0("<b>Name: </b>", OH_2024_ShinyG_Burning_Priorities_dropz$Name, "<br>",
                             "<b>Priority: </b>", OH_2024_ShinyG_Burning_Priorities_dropz$Priority, "<br>",
                             "<b>Description: </b>", OH_2024_ShinyG_Burning_Priorities_dropz$PopupInfo, "<br>",
                             "<b>Area Number: </b>", OH_2024_ShinyG_Burning_Priorities_dropz$AreaNumber, "<br>",
                             "<b>Species: </b>", OH_2024_ShinyG_Burning_Priorities_dropz$INSVNAME)) %>% # Optional: add popups
  addPolygons(data = OH_2024_Invasive_Species_Removed_dropz,
              group = "OH 2024 Invasive Species Removed",
              color = "#EE3377", # magenta #EE3377
              #color = "yellow",
              #fillColor = "yellow",
              fillOpacity = 0.6,
              popup = paste0("<b>Name: </b>", OH_2024_Invasive_Species_Removed_dropz$Name, "<br>",
                             "<b>Description: </b>", OH_2024_Invasive_Species_Removed_dropz$PopupInfo)) %>%
  addPolygons(data = OH_2024_Identified_Invasive_Species_Patches_dropz,
              # covers same area as Shiny g
              group = "OH 2024 Invasive Species Patches",
              # use a darker colour so lighter Shiny will show
              color = "#33BBEE", #cyan #33BBEE
              #fillColor = "orange",
              fillOpacity = 0.4,
              popup = paste0("<b>Name: </b>", OH_2024_Identified_Invasive_Species_Patches_dropz$Name, "<br>",
                             "<b>Description: </b>", OH_2024_Identified_Invasive_Species_Patches_dropz$PopupInfo, "<br>",
                             "<b>Area: </b>", OH_2024_Identified_Invasive_Species_Patches_dropz$AreaNumber, "<br>",
                             "<b>Species: </b>", OH_2024_Identified_Invasive_Species_Patches_dropz$INSVNAME)
              ) %>%
  addCircleMarkers(data = OH_2024_Invasive_Species_Points_dropz,
              group = "OH 2024 Invasive Species Points",
              color = "#CC3311", # CC3311 red
              #fillColor = "red",
              fillOpacity = 0.5,
              radius = 3,
              popup = paste0("<b>Name: </b>", OH_2024_Invasive_Species_Points_dropz$Name, "<br>",
                            "<b>Description: </b>", OH_2024_Invasive_Species_Points_dropz$Descript, "<br>",
                            "<b>Species: </b>", OH_2024_Invasive_Species_Points_dropz$INSVNAME, "<br>",
                            "<b>Elevation: </b>", OH_2024_Invasive_Species_Points_dropz$Elevation, "<br>",
                            "<b>Date: </b>", OH_2024_Invasive_Species_Points_dropz$DateTimeS)
              ) %>%
  # add legend to overlay group toggled off
  addLegend(
              "bottomright",
              colors = c("#AA4499", "#EECC66", "#EE3377", "#33BBEE", "#EE7733", "#CC3311"),
              labels = c("OH 2025 Completed polygons", "OH 2025 Experimental test plot points", "OH 2024 Invasive Species Removed", "OH 2024 Invasive Species Patches", "OH 2024 ShinyG Burning Priorities", "OH 2024 Invasive Species Points"),
              title = "OH Spatial Data",
              group = "LEGEND - OH Spatial Polygon Colour"
              ) %>%
  addMeasure(
    position = "topleft",
    primaryLengthUnit = "meters",
    primaryAreaUnit = "sqmeters",
    activeColor = "#DDAA33",
    completedColor = "#BB5566") %>% 
  addControl(title, position = "topright") %>%                         
  addLayersControl(
    overlayGroups = c("OH 2025 Completed polygons", "OH 2025 Experimental test plot points", "OH 2024 Invasive Species Removed", "OH 2024 Invasive Species Patches", "OH 2024 ShinyG Burning Priorities", "OH 2024 Invasive Species Points", "LEGEND - OH Spatial Polygon Colour"),
    options = layersControlOptions(collapsed = TRUE) # Makes control box always visible
  ) %>%
  hideGroup(c("OH 2025 Completed polygons", "OH 2025 Experimental test plot points", "OH 2024 ShinyG Burning Priorities", "OH 2024 Invasive Species Removed", "OH 2024 Invasive Species Patches", "OH 2024 Invasive Species Points", "LEGEND - OH Spatial Polygon Colour")) %>%
  addLegend("bottomright", pal = pal, values = HAT_sites_HAT$Site, title = "Site") %>%
              
  addScaleBar("topleft") %>%
  # setView(-123.44799, 48.52919, zoom = 11)
      setView(-123.45684, 48.49983, zoom = 11)
map_all
          # this needs to go at bottom of map code or else map gets cut off at bottom

```

### Oak Haven Spatial Data Geolocation Map
```{r leaflet-OH-spatial_geoloc, echo = FALSE, message = FALSE, include = TRUE}
################################################################################
# Interactive Geolocation map Developed by Wendy Anthony for HAT 2026-03-03
################################################################################
# library(leaflet.extras) # for addControlGPS() & addDrawToolbar()

title <- '<p style="text-align: center; height: 12px;"><span style="font-size:12px;font-weight:bold; background-color: rgba(255, 255, 255, 0.9;");>HAT GOE Monitoring Covenant Sites Map</span></p>'

map_OH_sp_geoloc <- leaflet() %>%
  # addTiles() %>%
  addProviderTiles("Esri.WorldImagery") %>%
  addPolygons(data = OHP_2025_Completed_polygons_dropz,
              group = "OH 2025 Completed polygons",
              color = "#AA4499", #AA4499 purple
              #fillColor = "purple",
              fillOpacity = 0.5,
              popup = paste0("<b>Name: </b>", OHP_2025_Completed_polygons_dropz$Name, "<br>",
                             "<b>Description: </b>", OHP_2025_Completed_polygons_dropz$PopupInfo)) %>%
  addCircleMarkers(data = OHP_2025_Experimental_test_plots_dropz,
              group = "OH 2025 Experimental test plot points",
              color = "#EECC66", #EECC66 light yellow
              #fillColor = "purple",
              fillOpacity = 0.8,
              weight = 1,
              radius = 3,
              popup = paste0("<b>Name: </b>", OHP_2025_Experimental_test_plots_dropz$Name, "<br>",
                            "<b>Description: </b>", OHP_2025_Experimental_test_plots_dropz$Descript, "<br>",
                            "<b>Date: </b>", OHP_2025_Experimental_test_plots_dropz$DateTimeS)) %>%
  addPolygons(data = OH_2024_ShinyG_Burning_Priorities_dropz,
              # covers same area as Invasive_Species_Patches
              group = "OH 2024 ShinyG Burning Priorities",
              # use a lighter colour so lighter Shiny will show over Species patches
              color = "#EE7733", #EE7733 orange
              #color = "blue",
              #fillColor = "blue",
              fillOpacity = 0.3,
              popup = paste0("<b>Name: </b>", OH_2024_ShinyG_Burning_Priorities_dropz$Name, "<br>",
                             "<b>Priority: </b>", OH_2024_ShinyG_Burning_Priorities_dropz$Priority, "<br>",
                             "<b>Description: </b>", OH_2024_ShinyG_Burning_Priorities_dropz$PopupInfo, "<br>",
                             "<b>Area Number: </b>", OH_2024_ShinyG_Burning_Priorities_dropz$AreaNumber, "<br>",
                             "<b>Species: </b>", OH_2024_ShinyG_Burning_Priorities_dropz$INSVNAME)) %>% # Optional: add popups
  addPolygons(data = OH_2024_Invasive_Species_Removed_dropz,
              group = "OH 2024 Invasive Species Removed",
              color = "#EE3377", # magenta #EE3377
              #color = "yellow",
              #fillColor = "yellow",
              fillOpacity = 0.6,
              popup = paste0("<b>Name: </b>", OH_2024_Invasive_Species_Removed_dropz$Name, "<br>",
                             "<b>Description: </b>", OH_2024_Invasive_Species_Removed_dropz$PopupInfo)) %>%
  addPolygons(data = OH_2024_Identified_Invasive_Species_Patches_dropz,
              # covers same area as Shiny g
              group = "OH 2024 Invasive Species Patches",
              # use a darker colour so lighter Shiny will show
              color = "#33BBEE", #cyan #33BBEE
              #fillColor = "orange",
              fillOpacity = 0.4,
              popup = paste0("<b>Name: </b>", OH_2024_Identified_Invasive_Species_Patches_dropz$Name, "<br>",
                             "<b>Description: </b>", OH_2024_Identified_Invasive_Species_Patches_dropz$PopupInfo, "<br>",
                             "<b>Area: </b>", OH_2024_Identified_Invasive_Species_Patches_dropz$AreaNumber, "<br>",
                             "<b>Species: </b>", OH_2024_Identified_Invasive_Species_Patches_dropz$INSVNAME)
              ) %>%
  addCircleMarkers(data = OH_2024_Invasive_Species_Points_dropz,
              group = "OH 2024 Invasive Species Points",
              color = "#CC3311", # CC3311 red
              #fillColor = "red",
              fillOpacity = 0.5,
              radius = 3,
              popup = paste0("<b>Name: </b>", OH_2024_Invasive_Species_Points_dropz$Name, "<br>",
                            "<b>Description: </b>", OH_2024_Invasive_Species_Points_dropz$Descript, "<br>",
                            "<b>Species: </b>", OH_2024_Invasive_Species_Points_dropz$INSVNAME, "<br>",
                            "<b>Elevation: </b>", OH_2024_Invasive_Species_Points_dropz$Elevation, "<br>",
                            "<b>Date: </b>", OH_2024_Invasive_Species_Points_dropz$DateTimeS)
              ) %>%
  # add legend to overlay group toggled off
  addLegend(
              "bottomright",
              colors = c("#AA4499", "#EECC66", "#EE3377", "#33BBEE", "#EE7733", "#CC3311"),
              labels = c("OH 2025 Completed polygons", "OH 2025 Experimental test plot points", "OH 2024 Invasive Species Removed", "OH 2024 Invasive Species Patches", "OH 2024 ShinyG Burning Priorities", "OH 2024 Invasive Species Points"),
              title = "OH Spatial Data",
              group = "LEGEND - OH Spatial Polygon Colour"
              ) %>%
  setView(-123.4471, 48.56419, 17) %>%
    # leaflet.extras
  addControlGPS(
    options = gpsOptions(
      position = "topleft",
      activate = TRUE,
      autoCenter = TRUE,
      maxZoom = 10,
      setView = TRUE
    )
  ) %>%
  addControl(title, position = "topright") %>% 
  addMeasure(
    position = "topleft",
    primaryLengthUnit = "meters",
    primaryAreaUnit = "sqmeters",
    activeColor = "#DDAA33",
    completedColor = "#BB5566")  %>%
  addLayersControl(
    overlayGroups = c("OH 2025 Completed polygons", "OH 2025 Experimental test plot points", "OH 2024 Invasive Species Removed", "OH 2024 Invasive Species Patches", "OH 2024 ShinyG Burning Priorities", "OH 2024 Invasive Species Points", "LEGEND - OH Spatial Polygon Colour"),
    options = layersControlOptions(collapsed = TRUE) # Makes control box always visible
  ) %>%
  hideGroup(c("OH 2024 ShinyG Burning Priorities", "OH 2024 Invasive Species Removed", "OH 2024 Invasive Species Patches", "OH 2024 Invasive Species Points", "LEGEND - OH Spatial Polygon Colour")) %>%
  addScaleBar("topleft")  %>%
  addDrawToolbar(
    targetGroup = "Markers Added - Draw Tool",
    markerOptions = TRUE,
    polylineOptions = FALSE,
    polygonOptions = FALSE,
    circleOptions = FALSE,
    rectangleOptions = FALSE,
    circleMarkerOptions = FALSE,
    editOptions = editToolbarOptions(selectedPathOptions = selectedPathOptions())
  ) %>%
  ##### this layer.getLatLng() function only works for points
   htmlwidgets::onRender("
    function(el, x) {
      this.on('draw:created', function(e) {
        var layer = e.layer;
        var coords = layer.getLatLng();
        console.log('Lat: ' + coords.lat + ', Lng: ' + coords.lng);
        // Add to a global variable or custom HTML element here
        alert('Point Saved: ' + coords.lat + ', ' + coords.lng);
      });
    }
    ") %>% 
    addLayersControl(
      overlayGroups = c("OH 2025 Completed polygons", "OH 2025 Experimental test plot points", "OH 2024 Invasive Species Removed", "OH 2024 Invasive Species Patches", "OH 2024 ShinyG Burning Priorities", "OH 2024 Invasive Species Points", "Markers Added - Draw Tool", "LEGEND - OH Spatial Polygon Colour"),
      options = layersControlOptions(collapsed = TRUE) # Makes control box always visible
    ) 

################################################################################
# lat long on click
# these get in the way of drawing polygons
# js_code <- "
# function(el, x) {
#   this.on('click', function(e) {
#     var coords = e.latlng;
#     var lat = coords.lat;
#     var lng = coords.lng;
#     var popup = L.popup()
#       .setLatLng(coords)
#       .setContent('Latitude: ' + lat.toFixed(4) + ', Longitude: ' + lng.toFixed(4))
#       .openOn(this);
#   });
# }
# "
# 
# map_OH_sp_geoloc <- map_OH_sp_geoloc %>%
#   onRender(js_code)

map_OH_sp_geoloc

# Save map as webpage
saveWidget(map_OH_sp_geoloc, "output/HAT_spatial_site_map_geoloc_draw_1.html")

```

### Datatable HAT 3-Sites
```{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))
           )))
```

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

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



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

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

```{r filter-crew-hours-all}
#############################################
htmltools::br()
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=55}
-----------------------------------------------

### ***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. <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: There is no volunteer data summarized</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(sd_crew_vol_inv_top5_sum, column = "Crew_Hours", statistic = "sum", digits = 2), span(class = "caption", "= Crew Hours"))
p(class = "container", class = "value", summarywidget(sd_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(sd_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 = sd_crew_vol_inv_top5_sum, group = ~ Site, multiple = T)
filter_checkbox(id = "Year", label = "Choose Year", sharedData = sd_crew_vol_inv_top5_sum, group = ~ Year, allLevels = TRUE)
filter_select(id = "Invasive_Species_Cleared", label = "Choose Species", sharedData = sd_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(sd_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", linewidth = 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(sd_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=80}
-----------------------------------------------

### ***Mean % Species Cover Data***
```{r}
htmltools::HTML("
  Cover data was collected using quadrat-sampling methods at Matson in July 2024 & 2025, and at Oak Haven in April 2024 & 2025, in treated and untreated plots. Site sampling GOM species during different seasons may not be as meaningful for comparison as sampling during the same seasons. Charts show the standard variation around the mean % cover.")
```


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


```{r mean-cover-nat, echo = FALSE, message = FALSE, warning = FALSE}
# ### Native Species (bar) 
# #############################################
# custom_colours_years <- c("2022" = "#ffff33", 
#                     "2023" = "#4daf4a", 
#                     "2024" = "#984ea3", 
#                     "2025" = "#ff7f00")
# #############################################
# 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", linewidth = 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 (mean value variation)
```{r mean-cover-nat-error-points, echo = FALSE, message = FALSE, warning = FALSE}

#############################################
custom_colours_treat <- c("Untreated" = "#d8b365", 
                    "Treated" = "#5ab4ac")

#############################################
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 = ifelse(lower < 0, 0, 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", linewidth = 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-inv, echo = FALSE, message = FALSE, warning = FALSE}
# ### Invasive Species
# #############################################
# # create custom colour-blind-friendly palette
# custom_colours_years <- c("2022" = "#ffff33", 
#                     "2023" = "#4daf4a", 
#                     "2024" = "#984ea3", 
#                     "2025" = "#ff7f00")
# 
# #############################################
# 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", linewidth = 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
#     ))
```

### Invasive Species (mean value variation)
```{r mean-cover-inv-error-points, echo = FALSE, message = FALSE, warning = FALSE}

#############################################
custom_colours_treat <- c("Untreated" = "#d8b365", 
                    "Treated" = "#5ab4ac")

#############################################
ggplotly(
  ggplot(sd_cover_inv, 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 = ifelse(lower < 0, 0, 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", linewidth = 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 = 1 # too far to right
    x = 0.5,
    # gives some space between x axis label and legend
    y = -0.2
    ))
```


```{r mean-cover-grs, echo = FALSE, message = FALSE, warning = FALSE}
# ### Mixed Grasses
# #############################################
# custom_colours_years <- c("2022" = "#ffff33", 
#                     "2023" = "#4daf4a", 
#                     "2024" = "#984ea3", 
#                     "2025" = "#ff7f00")
# 
# #############################################
# 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", linewidth = 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
#     ))
```


### Mixed Grasses (mean value variation)
```{r mean-cover-grs-error-points, echo = FALSE, message = FALSE, warning = FALSE}

#############################################
custom_colours_treat <- c("Untreated" = "#d8b365", 
                    "Treated" = "#5ab4ac")

#############################################
ggplotly(
  ggplot(sd_cover_grs, 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 = ifelse(lower < 0, 0, 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", linewidth = 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 = 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}
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_cov_nat_top5, 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 only top 5 Native Species. Error bars show 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-errorbar-top5-site-year, echo = FALSE, message = FALSE, warning = FALSE}
#############################################
custom_colours_treat <- c("Untreated" = "#d8b365", 
                    "Treated" = "#5ab4ac")

#############################################
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 = ifelse(lower < 0, 0, 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", linewidth = 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=105}
-----------------------------------------------

### ***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", linewidth = 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
    ))
```

### 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)
           ))))
```



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

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

```{r about-tabs}
#############################################
br()
br()
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;")
#############################################
# HTML("<strong>Created and Coded for HAT by Wendy Anthony</strong><br>
# <span style='font-size:75%';>wanthony@uvic.ca
# <br>
# Modified: 2026-02-21 @ 06:56</span>")

HTML("
<div style='font-size:80%; text-align:center;'>
<strong>Created and Coded for HAT <br>by Wendy Anthony</strong><br>
wanthony@uvic.ca 
<br>
Modified: 2026-03-08 @ 20:20</div>
")
hr(style = "border: 0.5px solid grey; width: 100%; margin: auto;")
br()
br()

```

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

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

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

### HAT Datasets
```{r about-datasets}
HTML("
       <h5>HAT Data of 9 HAT-only-Managed-Sites</h5>
     
  <span style='font-size:85%';>
  
     1. <strong>HAT Restoration Crew Site Data</strong> 
     <details open>
     <summary>Click to close/open Crew Site Data details</summary>
     <br> * <strong>Metrics</strong>: Daily and Yearly crew hours and biomass (metres<sup>3</sup>) and area (metres<sup>2</sup>) of invasive species removed; 
     <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
     </details>
     <br>
     
     2. <strong>Matson Mattocks Volunteer Field Logs</strong> 
     <details>
     <summary>Click open for Volunteer Field Logs details</summary>
     <br> * <strong>Metrics</strong>: Daily volunteer work hours and 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
     </details>
     <br>
     
     3. <strong>Cover Data 2024-2025</strong>  
     <details>
     <summary>Click open for Cover Data details</summary>
     <br> * <strong>Metrics</strong>: Cover Mean % (Native/Invasive & Treated/Untreated); Species Richness
     <br> * <strong>Sites</strong>: Matson, Oak Haven
     <br> * <strong>Datasets</strong>: <em>Cover Data 2024-2025</em> 
     </details>
     <br>
     
     4. <strong>Site Data</strong> 
     <details>
     <summary>Click open for Site Data details</summary>
     <br> * <strong>Metrics</strong>: Location; 2022-2025; Top 5 Invasive Species Removed, crew hours, biomass removed, hours per m<sup>3</sup>; 
     <br> * <strong>Sites</strong>: Havenwood, Matson, Oak Haven
     <br> * <strong>Data</strong>: <em>https://hat.bc.ca/community-based-restoration</em>
     </details>
     <br>
     
     5. <strong>Spatial Data</strong> 
     <details>
     <summary>Click open for Spatial Data details</summary>
     <br> * <strong>Metrics</strong>: 2023-2025  Invasive Species Removed; shiny geranium priorities; test plots
     <br> * <strong>Sites</strong>: Oak Haven
     <br> * <strong>Data</strong>: <em>Polygons and Points Shape files</em>
     </details>
     
     
  </span>
     ")
```


### How to Use This Interactive Tool
```{r about-use-tool}
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 about-analysis-tips}
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 about-proposal}
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
  ")
```



```{r session-info, include = FALSE}
# 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
** Remove code before handing over to HAT **
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 -->