I am writing in R and shiny to output a table using DT, and export only the selected rows but the modifier argument inside exportOptions for selected = TRUE is not working.
From what I have seen online, the code below should have worked.
ui <- fluidPage(sidebarLayout(sidebarPanel(), mainPanel(DTOutput("table"))))
server <- function(input, output, session) {
data <- mtcars
output$table <- renderDT({
datatable(data, extensions = 'Buttons', selection = 'multiple',
options = list(dom = 'Bfrtip',
buttons = list(list(extend = 'copy', text = 'Copy Selected',
exportOptions = list(modifier = list(selected = TRUE)))),
select = TRUE)
)
})
}
shinyApp(ui = ui, server = server)
However, this copies all visible rows on the page and not just the ones that are selected.
Changing the selection argument to “none” removes the ability to select rows altogether.
datatable(data, extensions = 'Buttons', selection = 'none',
options = list(dom = 'Bfrtip',
buttons = list(list(extend = 'copy', text = 'Copy Selected',
exportOptions = list(modifier = list(selected = TRUE)))),
select = TRUE)
)
Could anyone help me out as to why this is not working?
Package versions: DT_0.32 shiny_1.8.0
Then, somewhere online (embarrassingly I cannot find it again), I saw the below and it somehow works.
exportOptions = list(rows = '.selected')
Could anyone tell me what .selected is?
From a quick ChatGPT search, it thinks that this is not a valid command and .selected is a CSS class.
Orange is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.