1

My datatables contain empty columns. How I can easily hide/remove them in R Shiny?

## Data table output format
data_output <- function(data, targets_number) {
    DT::datatable(data, rownames= FALSE, filter = 'top', extensions = c('Buttons','FixedHeader', 'KeyTable'), options = list(columnDefs = list(list(
      targets = targets_number,
      render = JS(
        "function(data, type, row, meta) {",
        "return type === 'display' && data.length > 60 ?",
        "'<span title=\"' + data + '\">' + data.substr(0, 60) + '...</span>' : data;",
        "}")
    )), orderClasses = TRUE, scrollX = TRUE, scrollY= TRUE, lengthMenu = list(c(4, 25, 100, -1), c('4', '25', '100', 'All')), pageLength = 4, dom = 'lr<"sep">CBtip', buttons = c(I('colvis'), 'copy', 'excel'), fixedHeader = TRUE, keys = TRUE, autoWidth = TRUE, deferRender = TRUE), callback = JS('table.page(1).draw(false);'))
  }

output$drugTable <- renderDT ({data_output(drug_sql_data,13)})
shafee
  • 15,566
  • 3
  • 19
  • 47
AVE
  • 35
  • 4

1 Answers1

-1

I don't know what R Shiny is, but I've managed to hide all empty columns with this: https://stackoverflow.com/a/74808566/757201

Jos
  • 1,387
  • 1
  • 13
  • 27