Summary

Row1

Site 1

0

Site 2

0

Site 3

272

Row2

type 1

102

type 2

16

type 3

61

type 4

0

type 5

0

type 6

0

type 7

93

type 8

0

Row3

About

The CRUK MetaData Dashboard

This dashboard is built with R using the Rmakrdown framework and can easily reproduce by others. The code behind the dashboard available here

Data

Packages

Deployment and reproducibly

The dashboard was deployed to Github docs.

---
title: "Dashboard"
output: 
  flexdashboard::flex_dashboard:
    theme: 
      version: 5
      bootswatch: cosmo #flatly
    source_code: embed
    orientation: rows
    vertical_layout: fill
    navbar:
      - { href: https://github.com/cmclean5/CRUKScotlandMetaData, align: right, icon: "fa-github" }
---

```{r setup, include=FALSE}
library(flexdashboard)
library(reactable)
library(knitr)
library(readxl)
library(data.table)
library(stringr)
library(dplyr)
library(here)
library(shiny)

## How to add Rmarkdown flxdashboard to github,
## Ref: https://www.r-bloggers.com/2020/09/deploying-flexdashboard-on-github-pages/

source(here("Scripts/loadFunctions.R"))

ICONS=c("fa-hospital-symbol","fa-file-medical")
```

```{r read file, echo=FALSE, warning=FALSE}
  
   ## read virtual cancer cohort CDM's
   df = as.data.table(readxl::read_xlsx("vcohort_CDM.xlsx",sheet=1))

   ## data processing
   encoded     = c("Site","Cancer")

   ## check any duplicate rows per Site or Cancer type
   df = duplicate.rows(x=df, encoded=encoded[1])
   df = duplicate.rows(x=df, encoded=encoded[2])
   
   
   ## Convert our one-hot encoding for sites to data column called
   ## Site
   cnames    = colnames(df)
   col.indx  = grepl(encoded[1], cnames)
   site.type = gsub(encoded[1],"",cnames[col.indx])
   site.type = str_squish(site.type)
 
   Svals        = rep(0,length(site.type))
   names(Svals) = site.type
     
    df = df %>% 
        rowwise() %>% 
        mutate(tmp=site.type[which.max(c_across(cnames[col.indx]))]) %>% 
        ungroup %>% 
        select(-cnames[col.indx]) %>%
        mutate(Site=as.character(tmp)) %>%
        select(-tmp)

   reorder = unique(df$Site)
   Sindx   = table(df$Site)
   Svals[match(names(Sindx),names(Svals))]=Sindx
   Scols   = rep("#b2b2b2",length(Svals))
   
   ## Convert our one-hot encoding for v. cancer cohorts to data column called
   ## Cancer
   cnames      = colnames(df)
   col.indx    = grepl(encoded[2], cnames)
   tumour.type = gsub(encoded[2],"",cnames[col.indx])
   tumour.type = str_squish(tumour.type)
 
   Cvals        = rep(0,length(tumour.type))
   names(Cvals) = tumour.type
     
   ## Ref: https://stackoverflow.com/questions/64230674/how-to-turn-one-hot-encoded-variables-to-a-single-factor-in-r
   
    df = df %>% 
        rowwise() %>% 
        mutate(tmp=tumour.type[which.max(c_across(cnames[col.indx]))]) %>% 
        ungroup %>% 
        select(-cnames[col.indx]) %>%
        mutate(Cancer=as.character(tmp)) %>%
        select(-tmp)

   reorder = unique(df$Cancer)
   Cindx   = table(df$Cancer)
   Cvals[match(names(Cindx),names(Cvals))]=Cindx
   
   ##Cvals   = Cvals[match(reorder,names(Cvals))]
   
   ##Ccols   = c("info","warning","primary","success")
   Ccols  = rep("#f5a5dc",length(Cvals))
```

Summary
=======================================================================

Row1
----------------------------------------------

### Site 1
```{r}
valueBox(Svals[1],
         icon=ICONS[1],
         caption=names(Svals)[1],
         color=Scols[1])
```

### Site 2
```{r}
valueBox(Svals[2],
         icon=ICONS[1],
         caption=names(Svals)[2],
         color=Scols[2])
```

### Site 3
```{r}
valueBox(Svals[3],
         icon=ICONS[1],
         caption=names(Svals)[3],
         color=Scols[3])
```


Row2
----------------------------------------------

### type 1
```{r}
valueBox(Cvals[1],
         icon=ICONS[2],
         caption=names(Cvals)[1],
         color=Ccols[1])
```

### type 2
```{r}
valueBox(Cvals[2],
         icon=ICONS[2],
         caption=names(Cvals[2]),
         color=Ccols[2])
```

### type 3
```{r}
valueBox(Cvals[3],
         icon=ICONS[2],
         caption=names(Cvals)[3],
         color=Ccols[3])
```

### type 4
```{r}
valueBox(Cvals[4],
         icon=ICONS[2],
         caption=names(Cvals)[4],
         color=Ccols[4])
```

### type 5
```{r}
valueBox(Cvals[5],
         icon=ICONS[2],
         caption=names(Cvals)[5],
         color=Ccols[5])
```

### type 6
```{r}
valueBox(Cvals[6],
         icon=ICONS[2],
         caption=names(Cvals[6]),
         color=Ccols[6])
```

### type 7
```{r}
valueBox(Cvals[7],
         icon=ICONS[2],
         caption=names(Cvals)[7],
         color=Ccols[7])
```

### type 8
```{r}
valueBox(Cvals[8],
         icon=ICONS[2],
         caption=names(Cvals)[8],
         color=Ccols[8])
```

Row3
----------------------------------------------

```{r display table, echo=FALSE}
   reactable(df, 
             groupBy=c("Cancer","Site"),
             filterable=TRUE,
             searchable=TRUE,
             showPageSizeOptions=TRUE,
             paginateSubRows=TRUE,
             bordered=TRUE,
             outlined=TRUE,
             striped=TRUE,
             highlight=TRUE,
             wrap=FALSE,
             resizable=TRUE,
             selection="multiple",
             #defaultSelected=c(1,2),
             onClick="select",
             paginationType="jump",
             pageSizeOptions=c(25,50,100),
             defaultPageSize=25,
             theme=reactableTheme(borderColor="#dfe2ef",
                                  stripedColor="#f6f8fa",
                                  highlightColor="#f0f5f9",
                                  cellPadding="8px 12px",
                                  style=list(fontFamily="-apple-system, BlinkMacSystemFont, Segoe, UI, Helvetica, Arial, sans-serif"),
                                  searchInputStyle=list(width="100%"),
                                  rowSelectedStyle=list(backgroundColor="#eee",
                                                        boxShadow="inset 2px 0 0 0 #ffa62d")#,
                                  #headerStyle=list(borderColor="#555") 
                                  )
             )
```

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

**The CRUK MetaData Dashboard**

This dashboard is built with R using the Rmakrdown framework and can easily reproduce by others. The code behind the dashboard available [here](https://github.com/cmclean5/CRUKScotlandMetaData)

**Data**

**Packages**

* Dashboard interface - the [flexdashboard](https://rmarkdown.rstudio.com/flexdashboard/) package. 
* Data manipulation - [dplyr](https://dplyr.tidyverse.org/), and [tidyr](https://tidyr.tidyverse.org/)
* Tables - the [DT](https://rstudio.github.io/DT/) package

**Deployment and reproducibly**

The dashboard was deployed to Github docs.