Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy a Shiny DT row to users clipboard

Is there a way to have the selected row(s) in a shiny datatable (DT) be available for the user to copy (Ctrl+C) to their clipboard. Ideally it would also supply the data table's column names or headers.

UPDATE

global.R

library(rclipboard)
library(shiny)

ui.R:

...
rclipboardSetup(),
...
uiOutput("copy"),

server.R:

output$copy = renderUI({
    s = input$orders_rows_selected
    rclipButton("copybtm","Copy",data()[s,],icon("clipboard"))
  })
like image 532
theGreatKatzul Avatar asked Sep 10 '25 02:09

theGreatKatzul


1 Answers

Here is how to get a button to copy the selected rows. And there are the column headers too.

datatable(
  iris, 
  rownames = FALSE,
  extensions = c("Buttons", "Select"),
  options = 
    list(
      select = TRUE,
      dom = "Bfrtip",
      buttons = list(
        list(
          extend = "copy",
          text = 'Copy',
          exportOptions = list(modifier = list(selected = TRUE))
        )
      )
    )
)
like image 199
Stéphane Laurent Avatar answered Sep 12 '25 18:09

Stéphane Laurent