【发布时间】:2021-02-15 05:05:26
【问题描述】:
基于this 问题:我想在闪亮的数据表中选择一行,并将特定单元格的内容复制到剪贴板。
到目前为止我得到了什么:
library(DT)
ui <- basicPage(
h2("The mtcars data"),
DT::dataTableOutput("mytable")
)
server <- function(input, output) {
output$mytable <- DT::renderDataTable({
DT::datatable(mtcars,
rownames = FALSE,
extensions = c("Buttons", "Select"),
selection = 'none',
options =
list(
select = TRUE,
dom = "Bfrtip",
buttons = list(
list(
extend = "copy",
text = 'Copy',
exportOptions = list(modifier = list(selected = TRUE))
)
)
))
})
}
shinyApp(ui, server)
在选择第 1 行后使用此代码,我在剪贴板中获得了以下数据:
Exported data
mpg cyl disp hp drat wt qsec vs am gear carb
21 6 160 110 3.9 2.62 16.46 0 1 4 4
是否可以去掉表头并获取特定单元格的数据(例如disp)?
160
【问题讨论】:
-
datatables似乎没有内置功能,但你必须create your own button