From b8cda06d546699800058b4dd7864acd10d0ebc7a Mon Sep 17 00:00:00 2001 From: fawda123 Date: Wed, 13 Dec 2023 09:00:06 -0500 Subject: [PATCH] add better text callout for current and total summaries #3 --- R/funcs.R | 35 +++++++++++++++++++++++++++++++++++ docs/summaries.html | 21 ++++++++++++--------- docs/summaries.qmd | 15 ++++++++------- 3 files changed, 55 insertions(+), 16 deletions(-) diff --git a/R/funcs.R b/R/funcs.R index 60012ae..3b893ef 100644 --- a/R/funcs.R +++ b/R/funcs.R @@ -209,4 +209,39 @@ rdataload <- function(x){ return(out) +} + +# get summaries for inline text +summ_fun <- function(dat, yrrng = NULL){ + + if(!is.null(yrrng)){ + if(length(yrrng) == 1) + yrrng <- rep(yrrng, 2) + } else { + yrrng <- range(dat$Year) + } + + # data prep + rstsum <- dat %>% + filter(Year <= yrrng[2] & Year >= yrrng[1]) %>% + filter(!is.na(Activity)) %>% + summarise( + pro = n(), + acr = sum(Acres, na.rm = T), + mil = sum(Miles, na.rm = T), + par = length(unique(Partner)) + ) %>% + mutate( + acr = case_when( + acr < 1 & acr > 0 ~ '< 1', + T ~ format(round(acr, 0), big.mark = ',', trim = T) + ), + mil = case_when( + mil < 1 & mil > 0 ~ '< 1', + T ~ format(round(mil, 2), big.mark = ',', trim = T) + ) + ) + + return(rstsum) + } \ No newline at end of file diff --git a/docs/summaries.html b/docs/summaries.html index 44e4a81..0f992ed 100644 --- a/docs/summaries.html +++ b/docs/summaries.html @@ -114,18 +114,21 @@ -
-
17 protection projects to date.
+
+
71 projects in 2023, 826 projects to date
-
-
6 protection projects in 2023.
+
+
32,011 acres/1.66 miles in 2023, 167,749 acres/247.12 miles to date
+
+
+
21 partners involved in 2023, 84 partners involved to date


Projects in Tampa Bay by general habitat
-
- +
+


@@ -133,8 +136,8 @@
Projects in Tampa Bay by general habitat
Projects in Tampa Bay by primary habitat
-
- +
+
@@ -540,7 +543,7 @@

Total 2023 projects - + diff --git a/docs/summaries.qmd b/docs/summaries.qmd index ee049e3..8476291 100644 --- a/docs/summaries.qmd +++ b/docs/summaries.qmd @@ -27,10 +27,14 @@ library(here) library(reactable) library(dplyr) +source(here('R/funcs.R')) + load(file = here('data/rstdatall.RData')) load(file = here('tabs/gentab.RData')) load(file = here('tabs/pritab.RData')) cur <- max(rstdatall$Year) +curtxt <- summ_fun(rstdatall, cur) +alltxt <- summ_fun(rstdatall) ``` Data include habitat restoration projects conducted in Tampa Bay and its watershed from 1971 to the present. Records prior to 2006 were compiled during the Tampa Bay Estuary Program's Habitat Master Plan Update (HMP, 2020). Since 2006, habitat restoration data are reported to the Tampa Bay Estuary Program by regional partners and submitted each year to the US Environmental Protection Agency (EPA) through the National Estuary Program Online Reporting Tool (NEPORT) to conform to the Government Performance and Results Act (GPRA). @@ -43,15 +47,12 @@ Data include habitat restoration projects conducted in Tampa Bay and its watersh Summaries by primary habitat do not include "Protection" activities, which may include additional unnatural habitat categories not evaluated by the TBEP Habitat Master Plan. Primary habitat summaries are also only possible from 2006 to present. ::: -```{r} -prodat <- filter(rstdatall, Activity == 'Protection') -protot <- nrow(prodat) -procur <- prodat %>% filter(Year == cur) %>% nrow() -``` -##### **`r protot` protection projects** to date. +##### **`r curtxt$pro` projects** in `r cur`, **`r alltxt$pro` projects** to date + +##### **`r curtxt$acr` acres/`r curtxt$mil` miles** in `r cur`, **`r alltxt$acr` acres/`r alltxt$mil` miles** to date -##### **`r procur` protection projects** in `r cur`. +##### **`r curtxt$par` partners** involved in `r cur`, **`r alltxt$par` partners** involved to date