Using the DT-package :
# global.R
library(shiny) library(DT) sketch = htmltools::withTags(table( class = 'display', thead( tr( th(rowspan = 2, ''), th(rowspan = 2, 'Cohort'), th(colspan = 10, 'Wk') ), tr(lapply(paste(c('', 'f'), rep(1:5, each=2), sep=''), th)) ) ))
# ui.R
shinyUI( fluidPage( DT::dataTableOutput(outputId="table") ) )
# server.R
shinyServer(function(input, output, session) { output$table <- DT::renderDataTable({ df$flag <- as.factor(df$flag) x <- reshape(df, timevar = 'wk', sep = '_', direction = 'wide',idvar ='cohort') row.names(x) <- NULL colnames(x)[-1] <- paste(c('', 'f'), rep(1:5, each = 2), sep = '') datatable(x, rownames = T, container = sketch, options = list(dom = 'C<"clear">rti', pageLength = -1, columnDefs = list(list(visible = F, targets = c(3,5,7,9,11)))) )%>% formatStyle('1', 'f1', backgroundColor = styleEqual(c(0, 1), c('white','lightblue'))) %>% formatStyle('2', 'f2', backgroundColor = styleEqual(c(0, 1), c('white','lightblue'))) %>% formatStyle('3', 'f3', backgroundColor = styleEqual(c(0, 1), c('white','lightblue'))) %>% formatStyle('4', 'f4', backgroundColor = styleEqual(c(0, 1), c('white','lightblue'))) %>% formatStyle('5', 'f5', backgroundColor = styleEqual(c(0, 1), c('white','lightblue'))) }) })
\
