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
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
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'))))
Thanks again.
Sry I dont see it . 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?)
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.
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.