Weekly report dashboard

Row

All completed HH

Control

268

Intervention

244

Completed E3

93

Completed BP for child

400

Completed MDAT (60M)

512

Row

Pie chart for control vs intervention

Anthropo (average,max,min, SD of weight measurement)

Anthropo (average,max,min, SD of height measurement)

Completed CRFs by visit

Box plot to show the relationship between weight and height

THIS WEEK =======================================================================

Row

Completed CRFs this week

Control for this week

10

Intervention for this week

3

Anthopo completed this week

13

E3 completed this week

0

MDAT

Row

Completed MDAT this week

[1] "Date"
13

Row

Completed MDAT by domain (this week)

Chart of completed MDAT by domain since the start

### Chart of completed MDAT by domain this week

Data table

---
title: "Weekly Report Dashboard"
output: 
  flexdashboard::flex_dashboard:
    theme: cerulean
    orientation: rows
    vertical_layout: fill
    social: [ "whatsapp","email", "menu"]
    source_code: embed 
---

```{r setup, include=FALSE}
setwd("C:/Users/rwand/Documents/REPORTS/Dashboard")
library(flexdashboard)
library(knitr)
library(plotly)
library(openintro)
library(tidyverse)
library(highcharter)
library(ggplot2)
library(ggridges)
library(DT)
library(readr)
library(readxl)
library(plotrix) # for 3D pie chart
library(pagedown)  # so as to convert html in pdf
library(lattice)


weekly = Sys.Date() -7

data1 <- read_csv("HAPINIIRwanda_DATA.csv") %>% rename("id" ="record_id")
school <- read_csv("HAPINRwandaSchedulin_DATA.csv")

logbook <- read_excel("~/REPORTS/Dashboard/logbook.xlsx")
logbook<-logbook %>% select(id,TreatmentArm) %>% rename("Treatment Arm" =TreatmentArm)
```

```{r, include=FALSE}
# Removing blank rows

HAPINIIRwanda_DATA=data1[-(1:8),]

# Extracting C33 in all CRFs

C33_CRF_all=select(HAPINIIRwanda_DATA,id,redcap_event_name, starts_with("c33_"))

#Extracting complete cases

C33_CRF_all=C33_CRF_all[complete.cases(C33_CRF_all$c33_date_2),]

# Yearly data set

#c33_60 month                     
c33_60M_crf=C33_CRF_all %>% filter(redcap_event_name=="year_5_arm_1") 

## Exporting in excel
write.csv(c33_60M_crf,"c33_60M_crf.csv",row.names = FALSE)

#C31 CRFS
#============================================================================
# Extracting C31 in all CRFs
C31_CRF_all=select(HAPINIIRwanda_DATA,id,redcap_event_name, starts_with("c31_"))
#Extracting complete cases

C31_CRF_all=C31_CRF_all[complete.cases(C31_CRF_all$c31_date_2),]

# Yearly data set

#c33_60 month                     
c31_60M_crf=C31_CRF_all %>% filter(redcap_event_name=="year_5_arm_1") 
c31_54M_crf=C31_CRF_all %>% filter(redcap_event_name=="year_4_q3_arm_1")
## Exporting in excel
write.csv(c31_60M_crf,"c31_60M_crf.csv",row.names = FALSE )
#=========================================================================

# Extracting C32 in all CRFs
C32_CRF_all=select(HAPINIIRwanda_DATA,id,redcap_event_name, starts_with("c32_"))
#Extracting complete cases

C32_CRF_all=C32_CRF_all[complete.cases(C32_CRF_all$c32_date_2),]

# Yearly data set

#c32_60 month                     
c32_60M_crf=C32_CRF_all %>% filter(redcap_event_name=="year_5_arm_1") 

## Exporting in excel
write.csv(c32_60M_crf,"c32_60M_crf.csv",row.names = FALSE )

# C35 CRFs
#=======================================================================#
# Extracting C35 in all CRFs
C35_CRF_all=select(HAPINIIRwanda_DATA,id,redcap_event_name, starts_with("c35_")) 
#Extracting complete cases

C35_CRF_all=C35_CRF_all[complete.cases(C35_CRF_all$c35_date_2),] 

# Yearly data set

#c35_60 month                     
c35_60M_crf=C35_CRF_all %>% filter(redcap_event_name=="year_5_arm_1")

## Exporting in excel
write.csv(c35_60M_crf,"c35_60M_crf.csv",row.names = FALSE )

#=======================================================================#
# Extracting B11a in all CRFs

B11a_CRF_all=select(HAPINIIRwanda_DATA,id,redcap_event_name, starts_with("b11a_"))
#Extracting complete cases

B11a_CRF_all=B11a_CRF_all[complete.cases(B11a_CRF_all$b11a_date),] 

# Yearly data set

#B11a_60 month

b11a_60M_crf=B11a_CRF_all %>% filter(redcap_event_name =="year_5_arm_1")

## Exporting in excel

write.csv(b11a_60M_crf,"b11a_60M_crf.csv", row.names = FALSE )

#=======================================================================#

# Extracting C85 in all CRFs
C85_CRF_all=select(HAPINIIRwanda_DATA,id,redcap_event_name, starts_with("c85_"))
#Extracting complete cases

C85_CRF_all=C85_CRF_all[complete.cases(C85_CRF_all$c85_date),] 

# Yearly data set

c85_crf=C85_CRF_all
## Exporting in excel

write.csv(c85_crf,"c85_crf.csv",row.names = FALSE)

#==============================================================================

#c85_second assessment
#==========================================================================

# Extracting C85_second in all CRFs
C85_sec_CRF_all=select(HAPINIIRwanda_DATA,id,redcap_event_name, ends_with("_2"))
#Extracting complete cases

C85_sec_CRF_all=C85_sec_CRF_all[complete.cases(C85_sec_CRF_all$c85_date_2 ),]

C85_sec2_CRF_all=select(C85_sec_CRF_all,id,redcap_event_name, starts_with("c85_"))

#MDAT second assessment all
c85_second_assessment_crf=C85_sec2_CRF_all

## Exporting in excel

write.csv(c85_second_assessment_crf,"c85_second_assessment_crf.csv",row.names = FALSE )
#==================================================================================

#e3 CRFS
#============================================================================
# Extracting e3 in all CRFs
e3_CRF_all=select(HAPINIIRwanda_DATA,id,redcap_event_name, starts_with("e3_"))
#Extracting complete cases

e3_CRF_all=e3_CRF_all[complete.cases(e3_CRF_all$e3_date),]

# Yearly data set

#E3_24_36_48 and 60 month
e3=e3_CRF_all
## Exporting in excel

write.csv(e3,"e3_crf.csv",row.names = FALSE)
#=========================================================================

                      #H41 CRFS
#============================================================================
# Extracting H41 in all CRFs

H41_CRF_all=select(HAPINIIRwanda_DATA,id,redcap_event_name, starts_with("h41_"))

#Extracting complete cases

H41_all=H41_CRF_all[complete.cases(H41_CRF_all$h41_date_v2),] 

# Yearly data set

#h41_60 month

h41_60M_crf=H41_all %>% filter(redcap_event_name =="year_5_arm_1")
view(h41_60M_crf)
h41_54M_crf=H41_all %>% filter(redcap_event_name== "year_4_q3_arm_1")
## Exporting in excel

write.csv(h41_60M_crf,"h41_60M_crf.csv",row.names = FALSE)
#=========================================================================

                                      # H42 CRF
                    #_____________________________________#

# Extracting H42 in all CRFs
H42_CRF_all=select(HAPINIIRwanda_DATA,id,redcap_event_name, starts_with("h42_"))
#Extracting complete cases

H42_CRF_all=H42_CRF_all[complete.cases(H42_CRF_all$h42_date_2),]

# Yearly data set

#H42_60 month

h42_60M_crf=H42_CRF_all %>% filter(redcap_event_name =="year_5_arm_1")
h42_54M_crf=H42_CRF_all %>% filter(redcap_event_name == "year_4_q3_arm_1")

## Exporting in excel

write.csv(h42_60M_crf,"h42_60M_crf.csv",row.names = FALSE)
#-----------------------------------------------------------------------------

                                      # H43 CRF
                        #_____________________________________#

# Extracting H43 in all CRFs
H43_CRF_all=select(HAPINIIRwanda_DATA,id,redcap_event_name, starts_with("h43_")) 
#Extracting complete cases

H43_all=H43_CRF_all[complete.cases(H43_CRF_all$h43_date_2),] 

# Yearly data set

#H43_60 month

h43_60M_crf=H43_CRF_all %>% filter(redcap_event_name =="year_5_arm_1")

## Exporting in excel

write.csv(h43_60M_crf,"h43_60M_crf.csv", row.names = FALSE )
                                     # M10 CRF
                           #_____________________________________#

# Extracting M10 in all CRFs
M10_CRF_all=select(HAPINIIRwanda_DATA,id,redcap_event_name, starts_with("m10_"))
#Extracting complete cases

M10_CRF_all=M10_CRF_all[complete.cases(M10_CRF_all$m10_date),]

# Yearly data set

#m19 all month

m10_crf=M10_CRF_all

## Exporting in excel

write.csv(m10_crf,"m10_crf.csv",row.names = FALSE)
#_____________________________________________________________________
                                       # M11 CRF
                           #_____________________________________#

# Extracting M11 in all CRFs
M11_CRF_all=select(HAPINIIRwanda_DATA,id,redcap_event_name, starts_with("m11_"))
#Extracting complete cases

M11_CRF_all=M11_CRF_all[complete.cases(M11_CRF_all$m11_date),]

# Yearly data set

#m19 all month

m11_crf=M11_CRF_all

## Exporting in excel

write.csv(m11_crf,"m11_crf.csv",row.names = FALSE)
#_____________________________________________________________________
                                           # M19 CRF
                           #_____________________________________#

# Extracting M19 in all CRFs
M19_CRF_all=select(HAPINIIRwanda_DATA,id,redcap_event_name, starts_with("m19_"))
#Extracting complete cases

M19_CRF_all=M19_CRF_all[complete.cases(M19_CRF_all$m19_date),]

# Yearly data set

#m19 all month

m19_crf=M19_CRF_all

## Exporting in excel

write.csv(m19_crf,"m19_crf.csv",row.names = FALSE)
#_____________________________________________________________________
                                       # M14b CRF
                           #_____________________________________#

# Extracting M14b in all CRFs
M14b_CRF_all=select(HAPINIIRwanda_DATA,id,redcap_event_name, starts_with(c("m14_","m14b_")))
#Extracting complete cases

M14b_CRF_all=M14b_CRF_all[complete.cases(M14b_CRF_all$m14b_date),]

# Yearly data set

#m19 all month

m14b_crf=M14b_CRF_all

## Exporting in excel

write.csv(m14b_crf,"m14b_crf.csv",row.names = FALSE)
#_____________________________________________________________________

                                 # s4 CRF
                       #_____________________________________#

# Extracting S4 in all CRFs
S4_CRF_all=select(HAPINIIRwanda_DATA,id,redcap_event_name, starts_with("s4_"))
#Extracting complete cases

S4_CRF_all=S4_CRF_all[complete.cases(S4_CRF_all$s4_date),]

# Yearly data set

#S4 for all month

s4_crf=S4_CRF_all

## Exporting in excel

write.csv(s4_crf,"s4_crf.csv",row.names = FALSE)
#_____________________________________________________________________

                          # c88 CRF
          #_____________________________________#

# Extracting H41 in all CRFs
c88_CRF_all=select(HAPINIIRwanda_DATA,id,redcap_event_name, starts_with("c88_"))
#Extracting complete cases

c88_CRF_all=c88_CRF_all[complete.cases(c88_CRF_all$c88_date),]

# Yearly data set

#c88 for all month

c88_crf=c88_CRF_all

## Exporting in excel

write.csv(c88_crf,"c88_crf.csv",row.names = FALSE)
```


```{r, include=FALSE}
     ###____ Total number of MDAT completed _____###

                  ## INTERVENTION ##

c85_logbook =merge(c85_crf,logbook, by="id") 

# Completed in Intervention 

intervention = c85_logbook %>% 
  filter(`Treatment Arm`=="Intervention", redcap_event_name=="year_5_arm_1")

length(intervention$id)

  ## Previous wk

interventionWK = c85_logbook %>% 
  filter(`Treatment Arm`=="Intervention", redcap_event_name=="year_5_arm_1") %>% 
  filter(c85_date >= weekly) 
length(interventionWK$id)

# Completed in Control 

control = c85_logbook %>% 
  filter(`Treatment Arm`=="Control", redcap_event_name=="year_5_arm_1")

length(control$id)

## Previous wk
controlWK = c85_logbook %>%
  filter(`Treatment Arm`=="Control", redcap_event_name=="year_5_arm_1") %>% 
  filter(c85_date >= weekly)
length(controlWK$id)

## Total number of children completed MDAT_Social
c85_60 =c85_logbook %>% filter(redcap_event_name =="year_5_arm_1")
soc = c85_logbook %>% 
  select(c85_spoon_self_2:c85_toilet_self_2) %>% drop_na() 

all_social <- soc[apply(soc, 1, function(row) all(row == 1)), ]
length(all_social$c85_spoon_self_2)

## Social week

socWK = c85_logbook %>% 
  select(c85_date, c85_spoon_self_2:c85_toilet_self_2) %>%
  filter(c85_date>= weekly, c85_date < Sys.Date()) 
so1 = socWK %>% select(-c85_date)

all_socialWK <- so1[apply(so1, 1, function(row) all(row == 1)), ]
length(all_socialWK$c85_spoon_self_2)

## Total number of children completed MDAT_language

language = c85_60 %>% select(c85_5_identify:c85_place) 

all_language <- language[apply(language, 1, function(row) all(row == 1)), ] 
length(all_language$c85_5_identify)

# Language week
languageWK = c85_60 %>% select(c85_date, c85_5_identify:c85_place) %>% 
  filter(c85_date >= weekly)
language1 = languageWK %>% select(-c85_date) 

all_languagewk <- language1[apply(language1, 1, function(row) all(row == 1)), ] 
length(all_languagewk$c85_5_identify)

## Total number of children completed MDAT_Fine Moto

fine = c85_60 %>% 
  select(c85_4block:c85_top_sq)

all_fine <- fine[apply(fine, 1, function(row) all(row == 1)), ] 
length(all_fine$c85_4block)

# Fine Moto week
fineWK = c85_60 %>% 
  select(c85_date,c85_4block:c85_top_sq) %>%
  drop_na() %>% 
  filter(c85_date>= weekly) 
fi1 = fineWK %>% select(-c85_date)

all_finewk <- fi1[apply(fi1, 1, function(row) all(row == 1)), ]
length(all_finewk$c85_4block)

## Total number of children completed MDAT_Gross Moto

gross = c85_60 %>% select(c85_run:c85_basket_2m) %>% 
  drop_na() 

all_gross <- gross[apply(gross, 1, function(row) all(row == 1)), ] 
length(all_gross$c85_run)

# Gross Moto week

grosswk = c85_60 %>% select(c85_date, c85_run:c85_basket_2m) %>%
  drop_na() %>% 
  filter(c85_date >= weekly) 

go1 = grosswk %>% select(-c85_date)

all_grossWK <- go1[apply(go1, 1, function(row) all(row == 1)), ] 

length(all_grossWK$c85_run)

domain = data.frame(MDAT_Domain = c("Number of children who completed MDAT_Intervention",
                                    "Number of children who completed MDAT_control",
                                    "Total number of children who completed MDAT_Social",
                                    "Total number of children who completed MDAT_Language",
                                    "Total number of children who completed MDAT_Fine Motor",
                                    "Total number of children who completed MDAT_Gross Motor"),
                    Since_the_start = c(length(intervention$id),
                                        length(control$id),
                                        length(all_social$c85_spoon_self_2),
                                        length(all_language$c85_5_identify),
                                        length(all_fine$c85_4block),
                                        length(all_gross$c85_run)),
                    This_week = c(length(interventionWK$id),
                                  length(controlWK$id),
                                  length(all_socialWK$c85_spoon_self_2),
                                  length(all_languagewk$c85_5_identify),
                                  length(all_finewk$c85_4block),
                                  length(all_grossWK$c85_run))) 
```

```{r}
c33_60M_crf$id = as.numeric(c33_60M_crf$id)
c33_60 <- left_join(logbook, c33_60M_crf, by = "id")
c33_60_complete <- c33_60[complete.cases(c33_60$redcap_event_name), ]
c33_60_complete <- c33_60_complete %>% distinct(id, .keep_all = TRUE)
```

Weekly report dashboard
=======================================================================

Row
-----------------------------------------------------------------------

### All completed HH

```{r}
#valueBox(length(c33_60_complete$id), icon = "fa-building")
gauge(length(c33_60_complete$id), min = 0, max = 750,
      gaugeSectors(success = c(500,750),
                   colors = "blue"))
```

### Control

```{r}
control <- c33_60_complete %>% 
  filter(`Treatment Arm`== "Control")

valueBox(length(control$id), 
         icon = "fa-socks")
```

### Intervention

```{r}
intervention <- c33_60_complete %>% 
  filter(`Treatment Arm`== "Intervention")

valueBox(length(intervention$id), 
         icon = "fa-truck")
```

### Completed E3

```{r}
e = e3 %>% filter(redcap_event_name=="year_5_arm_1")

valueBox(length(e$id),color = "#E52356", icon = "fa-house")
```

### Completed BP for child

```{r}
bp = c88_crf %>% select(id,c88_date)

valueBox(length(bp$id), icon = "fa-baby")
```

### Completed MDAT (60M)

```{r}
mdat = C85_CRF_all %>% filter(redcap_event_name=="year_5_arm_1") 

valueBox(length(mdat$c85_date), icon = "fa-child")
```

Row
-----------------------------------------------------------------------

### Pie chart for control vs intervention 

```{r, fig.dim=0.1}
CI <- c33_60_complete %>% 
  group_by(`Treatment Arm`) %>% 
  summarise(Total = n())  

plot_ly(CI) %>% 
  add_pie(CI, labels=~`Treatment Arm`,values=~`Total`, 
          type="pie", hole=0.5)
```

### Anthropo (average,max,min, SD of weight measurement)

```{r}
c33_60_complete$c33_ave_wt_2 <- c33_60_complete$c33_ave_wt_2[(c33_60_complete$c33_wt1_2+c33_60_complete$c33_wt2_2)/2]
c33_60_complete$c33_ave_ht_2 <- c33_60_complete$c33_ave_ht_2[(c33_60_complete$c33_ht1_2+c33_60_complete$c33_ht2_2)/2]

antr_weight <- data.frame(
  measurement = c("Average", "Maximum", "Minimum", "Standard Deviation"),
  value = c(round(mean(c33_60_complete$c33_ave_wt_2), digits = 2),
    max(c33_60_complete$c33_ave_wt_2),
    min(c33_60_complete$c33_ave_wt_2),
    round(sd(c33_60_complete$c33_ave_wt_2), digits = 2)))


# Create the bar plot
ggplot(antr_weight, aes(x = measurement, y = value, fill = measurement)) +
  geom_bar(stat = "identity", show.legend = TRUE, width = 0.6) + # Create bars with legend
  geom_text(aes(label = value), vjust = -0.3, size = 4) +       # Add value on top of each bar
  scale_fill_brewer(palette = "Set2") +                        # Use a visually pleasing palette
  labs(
    title = "Summary Statistics Bar Plot",
    x = "Measurement",
    y = "Value",
    fill = "Measurement Type"
  ) +
  ylim(0,25) +
  theme_minimal() +
  theme(
    axis.text.x = element_text(angle = 45, hjust = 1),         # Rotate x-axis labels for readability
    legend.position = "bottom"
  )

# Assuming c33_60_complete is already defined and contains c33_ave_wt_2
# Create a data frame with raw data
#raw_data <- data.frame(value = c33_60_complete$c33_ave_wt_2)

# Calculate summary statistics
#summary_stats <- data.frame(
#  stat = c("Mean", "Maximum", "Minimum", "Standard Deviation"),
#  value = c(
#    round(mean(c33_60_complete$c33_ave_wt_2), 2),
#    max(c33_60_complete$c33_ave_wt_2),
#    min(c33_60_complete$c33_ave_wt_2),
#    round(sd(c33_60_complete$c33_ave_wt_2), 2)
#  )
#)

# Create the box plot
#ggplot(raw_data, aes(x = "", y = value)) +
 # geom_boxplot(fill = "skyblue", outlier.color = "red", width = 0.5) +
#  geom_point(data = summary_stats, aes(x = "", y = value, color = stat), size = 3) +
#  labs(
#    title = "Box Plot with Summary Statistics",
 #   y = "Values",
 #   x = "",
 #   caption = "Red points represent summary statistics."
 # ) +
 # theme_minimal() +
#  theme(legend.position = "bottom")


```

### Anthropo (average,max,min, SD of height measurement)

```{r}
antr_height <- data.frame(
  measurement = c("Average", "Maximum", "Minimum", "Standard Deviation"),
  value = c(round(mean(c33_60_complete$c33_ave_ht_2), digits = 2),
    max(c33_60_complete$c33_ave_ht_2),
    min(c33_60_complete$c33_ave_ht_2),
    round(sd(c33_60_complete$c33_ave_ht_2), digits = 2)))


# Create the bar plot
ggplot(antr_height, aes(x = measurement, y = value, fill = measurement)) +
  geom_bar(stat = "identity", show.legend = TRUE, width = 0.6) + # Create bars with legend
  geom_text(aes(label = value), vjust = -0.3, size = 4) +       # Add value on top of each bar
  scale_fill_brewer(palette = "Set2") +                        # Use a visually pleasing palette
  labs(
    title = "Summary Statistics Bar Plot",
    x = "Measurement",
    y = "Value",
    fill = "Measurements"
  ) +
  ylim(0,120) +
  theme_minimal() +
  theme(
    axis.text.x = element_text(angle = 45, hjust = 1),         # Rotate x-axis labels for readability
    legend.position = "bottom"
  )
```

### Completed CRFs by visit

```{r}
co <- H41_all %>%
  select(redcap_event_name, h41_date) %>% 
  mutate(
    event_name = case_when(
      redcap_event_name == "year_3q1_arm_1" ~ "Year 3",
      redcap_event_name == "year_3_q3_arm_1" ~ "Year 3 Subsample",
      redcap_event_name == "year_4_q1_arm_1" ~ "Year 4",
      redcap_event_name == "year_4_q3_arm_1" ~ "Year 4 Subsample",
      redcap_event_name == "year_5_arm_1" ~ "Year 5",
      TRUE ~ "Other")) %>% 
  group_by(event_name) %>% 
  summarise(Total = n(), .groups = "drop") 

# Create a bar chart
bar <- ggplot(data = co, aes(x = event_name, y = Total, fill = event_name)) +
  geom_col(position = "dodge") + # Create the bars
  geom_text(aes(label = Total), vjust = -0.5, size = 4) + # Add values on top of bars
  labs(
    title = "Completed CRFs by visits",
    x = "Event Name",
    y = "Total Count",
    fill = "Legend") + # Title for the legend
  scale_y_continuous(limits = c(0, 800)) +
  theme_minimal() + # Clean theme
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) # Rotate x-axis labels

# Display the plot
print(bar)
```

### Box plot to show the relationship between weight and height

```{r}
c88 = c88_crf %>% 
  mutate(Gender = ifelse(c88_sex==1, "Male", "Female")) %>% 
  group_by(Gender) #%>% summarise(Systolic = max(c88_ave_sbp, na.rm = T)) 

bwplot(Gender ~ c88_ave_sbp, data=c88, xlab = "BP systolic")
```
THIS WEEK
=======================================================================

Row
-----------------------------------------------------------------------

### Completed CRFs this week

```{r}
allwk = c33_60_complete %>% filter(c33_date_2 >= weekly, c33_date_2 < Sys.Date())
gauge(length(allwk$id), min = 0, max = 16, symbol = "HHDs",
      gaugeSectors(success = c(4,16),
                   warning = c(2, 3),
                   danger = c(0, 1),
                   colors = "green"))
```

### Control for this week

```{r}
controlwkl <- c33_60_complete %>% 
  filter(`Treatment Arm`== "Control", c33_date_2 >= weekly, c33_date_2 < Sys.Date())

valueBox(length(controlwkl$id), 
         icon = "fa-socks")
```

### Intervention for this week

```{r}
interventionwkl <- c33_60_complete %>% 
  filter(`Treatment Arm`== "Intervention", c33_date_2 >= weekly, c33_date_2 < Sys.Date())

valueBox(length(interventionwkl$id), 
         icon = "fa-truck")
```

### Anthopo completed this week

```{r}
#class(c33_60_complete$c33_date)
c33wk = c33_60_complete %>% select(id,c33_date_2) %>% 
  filter(c33_date_2 >= weekly, c33_date_2 < Sys.Date())

valueBox(length(c33wk$id), icon = "fa-building")
```

### E3 completed this week

```{r}
ewk = e3 %>% filter(redcap_event_name=="year_5_arm_1", e3_date >= weekly)

valueBox(length(ewk$id),color = "#F31C11", icon = "fa-house")
```

MDAT
=======================================================================

Row
-----------------------------------------------------------------------

### Completed MDAT this week

```{r}
class(c85_crf$c85_date)
mdatwk = c85_crf %>% select(id,redcap_event_name,c85_date) %>% 
  filter(redcap_event_name == "year_5_arm_1"  & c85_date >= weekly & c85_date < Sys.Date()) 

valueBox(length(mdatwk$id),color = "magenta", icon = "fa-child")
```

Row
-----------------------------------------------------------------------

### Completed MDAT by domain (this week)

```{r}
?barchart
barchart(MDAT_Domain ~ This_week, data=domain, 
         xlab = "Level",
        main = "Completed MDAT by domain (this week)",aspect = "fill",
       panel = lattice.getOption("panel.barchart"),
         default.prepanel = lattice.getOption("prepanel.default.barchart"),
         box.ratio = 2)
```

### Chart of completed MDAT by domain since the start

```{r}
# Replace with relevant columns for your dataset
ggplot(domain, aes(x = MDAT_Domain, y = Since_the_start, fill = MDAT_Domain)) +
  geom_col() +
  labs(title = "Bar Chart of completed MDAT by domain", x = "MDAT_Domain", y = "Count") +
  theme_minimal()
```
### Chart of completed MDAT by domain this week

```{r}
# Replace with relevant columns for your dataset
ggplot(domain, aes(x = MDAT_Domain, y = This_week, fill = MDAT_Domain)) +
  geom_col() +
  geom_text(aes(label = This_week), vjust = -0.5, size = 4) +
  labs(title = "Bar Chart of completed MDAT by domain this week", x = "MDAT_Domain", y = "Count") +
  theme_minimal() 
```


### Data table

```{r}
datatable(domain)
```


```{r}
# Convert HTML to PDF

pagedown::chrome_print(
  input = "Weekly_Report_Dashboard.html", 
  output = "Weekly_Report_Dashboard.pdf",
  extra_args = c("--print-to-pdf-no-header", "--margin-top=10mm", "--margin-bottom=10mm"))
```