Copy a Shiny DT row to users clipboard

不羁的心 提交于 2021-02-07 19:51:49

问题


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

回答1:


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


来源:https://stackoverflow.com/questions/45803153/copy-a-shiny-dt-row-to-users-clipboard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!