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)})

1 Answer 1

-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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.