Datatable has unrequested padding

I am rendering a datatable and get a style padding=10px inserted in the 1 or 2 td elements. The datatable is created directly from a csv. The csv has no hidden characters:

prevalences              <- read.csv(file = "data/Prevalences15.csv", stringsAsFactors=FALSE )

output$prevtab <- DT::renderDataTable({
    if (is.null(input$selected.indicator)) return()
    # get selected table
    prev.1 <- prevalences %>% filter(indicator == input$selected.indicator)

    # delete rows that are notes
    prev.1a <- prev.1 %>% filter(! startsWith(rowtype, "note"))

    # delete empty columns
    prev.2 <- prev.1a[ , colSums(prev.1 != "") != 0]
   # do some conditional formatting based on *R *S in cell text
    for (i in 1:dim(prev.2)[1]) {
      for (j in 1:dim(prev.2)[2]) {
        # get cell content
         piece <- prev.2[i,j];
         if (grepl('\\*R',piece)) {
         piece <- substr(piece,1,str_locate(piece,'\\*R')-1); 
         prev.2[i,j] <- paste0("<span style='color:red; display: block'>",piece,"</span>");
          } else if (grepl('\\*S',piece)) {
         piece <- substr(piece,1,str_locate(piece,'\\*S')-1); 
         prev.2[i,j] <- paste0("<span style='color:orange; display: block'>",piece,"</span>");
    # make columns headers and row names bold, indent the levels of a breakdown
        prev.3 <- datatable(prev.2,rownames = F, class='compact', escape = F, colnames=c(rep("", dim(prev.2)[2])), 
               options = list(dom = 't', bSort=F, paging=F,
                             columnDefs = list(list(visible=FALSE, targets=c(0,1,2,3,4)))
                             )) %>%
              formatStyle('rowtype', target='row',
                          fontWeight = styleEqual(c('columnheader1', 'columnheader2'),c('bold', 'bold')),
                          backgroundColor = styleEqual(c('columnheader1', 'columnheader2'),c('grey', 'lightgrey'))) %>%
              formatStyle('rowname', valueColumns = 'rowtype',
                          fontWeight = styleEqual(c('header'),c('bold'))) %>%
              formatStyle('rowname', valueColumns = 'rowtype',
                          padding = styleEqual(c('level'),c('10px')))


The output has these unexpected style elements:


I know its a pain to look deeply at code like this - but any pointers as to what might be going wrong?

Your image is a little small to see what is going on :stuck_out_tongue: Could you try to post a bigger one? Thank you!

Sorry about that! The first two have a style attribute that indents 10px, but in all the other rows the first column does not have this ident (which I don't want :slight_smile: )

1 Like