1. Description of the Goal

  1. The Extent of Implementation Support: CANS implementation across key processes for achieving child and family goals;
  2. The Extent of Agreement: Consensus on CANS implementation progress.

2. StyleInterval and StyleColorBar

#styleInterval
#styleColorBar
#install.packages('DT')
library(DT)

#Generate mock data complying with the data strucure we have; will replace this with real data later
Implement <- as.data.frame(cbind(matrix(round(runif(35,0,3),2),7)))
Consensus <- as.data.frame(cbind(matrix(round(runif(35,50,100),2),7)))
ColName <- c("Screening","Assessment","Treatment Planning","Reassessment","Linkage/Transition Planning")
RowName <- c("Use","Implementation","Protocol","Training","Practice Feedback","Outcome Feedback","Policy or System Change")
rownames(Implement) <- RowName
colnames(Implement) <- ColName
rownames(Consensus) <- RowName
colnames(Consensus) <- ColName

#Set up breaks and colors
brks <- quantile(Implement, probs = seq(.05, .95, .05), na.rm = TRUE, names = FALSE)
clrs <- round(seq(255, 40, length.out = length(brks) + 1), 0) %>%
{paste0("rgb(", .,",", .,",220)")}

#Implement heatmap with StyleInterval
datatable(Implement,options = list(
  autoWidth = TRUE, columnDefs = list(list(width = '100px',targets = 1:5))
  ))%>%formatStyle(names(Implement),background = styleInterval(brks,clrs))
#Implement barplot with StyleColorBar
datatable(Consensus, options = list(
  autoWidth = TRUE, columnDefs = list(list(width = '100px',targets = 1:5))
))%>% formatStyle(names(Consensus),
  background = styleColorBar(range(Consensus,40), 'steelblue'),
  backgroundSize = '98% 88%',
  backgroundRepeat = 'no-repeat',
  backgroundPosition = 'center')
ConsensusCompl <- 100 - Consensus
datatable(cbind(Implement,ConsensusCompl), options = list(
  autoWidth = TRUE, columnDefs = list(list(width = '100px',targets = 1:5), list(visible = FALSE, targets = 6:10))
 ))%>% 
formatStyle(names(Implement),backgroundColor = styleInterval(brks,clrs)) %>%
formatStyle(1:5,6:10,
  background = styleColorBar(c(0,60), 'rgba(255, 255, 255, 0.95)',angle = -90),
  backgroundSize = '100% 100%',
  backgroundRepeat = 'no-repeat',
  backgroundPosition = 'center') 

3. Plotly package

#install.packages('plotly')
library(plotly)

ImplementM <- as.matrix(Implement)

#Customize the scaling
vals <- unique(scales::rescale(c(ImplementM)))
o <- order(vals, decreasing = FALSE)
cols <- scales::col_numeric("Blues", domain = NULL)(vals)
colz <- setNames(data.frame(vals[o], cols[o]), NULL)

p <- plot_ly(
    x = ColName, y = RowName,
    z = ImplementM, type = "heatmap",colorscale = colz
)

#Now let's see the interactive plot
p
ConsensusM <- as.matrix(Consensus)
p <- plot_ly( x = ~rep(RowName,5), y = ~rep(ColName,7), z = ~c(ImplementM),
        marker = list(color = ~c(ConsensusM), colorscale = c('#FFE1A1', '#683531'), showscale = TRUE))%>%
 add_markers() %>%
  layout(annotations = list(
           x = 1.13,
           y = 1.05,
           text = 'Consensus',
           showarrow = FALSE
         ))

p