I'm looking for a library in R that can generate the results as attached in the picture i.e. multiple columnnames and rownames. Currently i'm using rpivotTable and DT::Datatable library for the same purpose and building a ShinyApp using them.
But the Problem that i'm facing with them is in exportation of output to excel using ShinyApp, which either comes with wrong repetition of headers or skipping of headers. e.g when i download the output of Iris as given in codes below, i don't get top headers of Sepal and Petal.
I need this
library(shiny)
library(DT)
iris<-iris[,c(5,1:4)]
ui =basicPage(
tags$head(
tags$style(type = "text/css",
HTML("th { text-align: center; }")
)
),
selectInput(inputId = "Species",
label = "Species:",
choices = c("All",
unique(as.character(iris$Species)))),
h2('Iris Table'),
DT::dataTableOutput('mytable')
)
server = function(input, output) {
output$mytable = DT::renderDataTable({
# a custom table container
sketch = htmltools::withTags(table(
class = 'display',
thead(
tr(
th(rowspan = 2, 'Species'),
th(colspan = 2, 'Sepal'),
th(colspan = 2, 'Petal')
),
tr(
lapply(rep(c('Length', 'Width'), 2), th)
)
)
))
DT::datatable(filter = "top", rownames = FALSE, container = sketch,
extensions = 'Buttons',
escape = FALSE,
options = list(dom = 'Bfrtip',
buttons =
list('colvis', list(
extend = 'collection',
buttons = list(list(extend='csv',
filename =
'hitStats'),
list(extend='excel',
filename =
'hitStats'),
list(extend='pdf',
filename=
'hitStats'),
list(extend='copy',
filename =
'hitStats'),
list(extend='print',
filename =
'hitStats')),
text = 'Download'
)),
scrollX = TRUE,
pageLength = nrow(iris),
order=list(list(2,'desc'))),
{
data<-iris
if(input$Species != 'All'){
data<-data[data$Species == input$Species,]
}
# data<-data[,c("Species",input$columns),drop=FALSE]
#
data
})
})
}
shinyApp(ui = ui, server = server)