Get list of visible columns of DT::datatable

shiny
datatable

#1

Hi,
I have a DT::datatable with Buttons extensions (for controling which columns are visible by user) in shiny app.
Is there a way how to get vector of actually visible columns?
Thank you


#2

Please refer to the DT: An R interface to the DataTables library.


#3

Hi englianhu,
thank you. I know this page and went through it before asking the question here. It is definitely possible that I missed it but I just dont see it there (I know how to get vector of visible rows but not columns). Could you be more specific?
Thanks


#4

YOu can try to refer to below sample.

trn %>% DT::datatable(caption = "Transaction Table", 
                              escape = FALSE, filter = 'top', rownames = FALSE, 
                              extensions = list('ColReorder' = NULL, 'RowReorder' = NULL, 
                                                'Buttons' = NULL, 'Responsive' = NULL), 
                              options = list(dom = 'BRrltpi', scrollX = TRUE, #autoWidth = TRUE, 
                                             lengthMenu = list(c(10, 50, 100, -1), c('10', '50', '100', 'All')), 
                                             ColReorder = TRUE, rowReorder = TRUE, 
                                             buttons = list('copy', 'print', 
                                                            list(extend = 'collection', 
                                                                 buttons = c('csv', 'excel', 'pdf'), 
                                                                 text = 'Download'), I('colvis'))))

#5

Thanks again.
Sry I dont see it :slight_smile: . I need to get list of actualy visible columns into R. The snippet you shared, as far as I know, enables user to change columns' visibility and/or download the dataset (the selected columns). However the download is done (again, as I understand it) via the DT javascript, so it does not help me determining which columns are visible, or does it?)


#6

List of visible columns can be found in

input$tableId_state$columns

Note that shiny returns state information only if stateSave parameter of renderDataTable function options list is set to TRUE.
I also strongly recommend adding to renderDataTable options list
stateLoadParams = DT::JS("function (settings, data) {return false;}")
to to avoid loading previous state of the table.


#7

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.