[英]Users were able to download table after edit the headers in DT R Shiny
This is an example the users can edit the headers of column names, I want to add the download button and the users can download the table after edit the header, how I can save the table after they edit.这是一个用户可以编辑列名标题的例子,我想添加下载按钮,用户可以在编辑 header 后下载表格,我如何在他们编辑后保存表格。 I am appreciated any help我很感激任何帮助
library(shiny)
library(DT)
callback <- c(
"$.contextMenu({",
" selector: '#table th',",
" trigger: 'right',",
" autoHide: true,",
" items: {",
" text: {",
" name: 'Enter column header:',",
" type: 'text',",
" value: ''",
" }",
" },",
" events: {",
" show: function(opts){",
" $.contextMenu.setInputValues(opts, {text: opts.$trigger.text()});",
" },",
" hide: function(opts){",
" var $this = this;",
" var data = $.contextMenu.getInputValues(opts, $this.data());",
" var $th = opts.$trigger;",
" $th.text(data.text);",
" }",
" }",
"});"
)
ui <- fluidPage(
tags$head(
tags$link(
rel = "stylesheet",
href = "https://cdnjs.cloudflare.com/ajax/libs/jquery-contextmenu/2.8.0/jquery.contextMenu.min.css"
),
tags$script(
src = "https://cdnjs.cloudflare.com/ajax/libs/jquery-contextmenu/2.8.0/jquery.contextMenu.min.js"
)
),
DTOutput("table")
)
server <- function(input, output){
output[["table"]] <- renderDT({
datatable(iris, callback = JS(callback))
}, server = FALSE)
}
shinyApp(ui, server)
You just have to use the Buttons
extension:你只需要使用Buttons
扩展:
output[["table"]] <- renderDT({
datatable(iris,
callback = JS(callback),
extensions = "Buttons",
options = list(
dom = "Bfrtip",
buttons = list("excel")
)
)
}, server = FALSE)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.