Bug in datatable with caption and fixedRownames

Viewed 241

I am trying to build datatable with fixedheader, fixed rownames, and a title. That's the code i am using:

library(DT)
library(shiny)


ui <- basicPage(
  DT::dataTableOutput("mytable")
)

server <- function(input, output) {
  m = as.data.frame(round(matrix(rnorm(10000), 20), 5))
  data<-datatable(
    m, extensions =  c('FixedColumns',"FixedHeader"),
    caption ='long title',
    options = list(
      scrollX = TRUE, scrollY = 300,
      paging=F,
      fixedColumns = list(leftColumns = 1)
    ))
  
  output$mytable = DT::renderDataTable({
    data
  })
}

shinyApp(ui, server)

When running the code you can see that the title is forcing the first column to take a new line. I tried using this code:

 caption = htmltools::tags$caption(
      style = 'caption-side: top; text-align: center;',   
      'long title'
    )

It worked when the caption-side was set to bottom but not top

Any idea how i can keep the caption-side:top and make it work

Appreciate your help

Thanks

1 Answers

Not a complete answer, but...

The problem is caused by fixedColumns = list(leftColumns = 1). Comment it out, and the table displays correctly. Also, I notice that "long title" appears in the header as soon as the table displays. "title", immediately below, appears only when the table is populated. That may be causing the undesirable offset.

FixedColumns seems to be a problematic DT extension. See here for example.

I understand why you want the fixed column. The bug appears to be in the extension rather than in DT itself. Sorry I can't be of more help.

Related