简体   繁体   English

如何在Shiny中使数据表可编辑

[英]How to make datatables editable in Shiny

I have managed to build a shiny app that reads csv files in datatables but my problem is now making the output editable. 我设法建立了一个闪亮的应用程序,可以读取数据表中的csv文件,但是现在我的问题是使输出可编辑。 I tried to use jquery.jeditable.js but it is not working. 我尝试使用jquery.jeditable.js,但无法正常工作。 Below is the full code I built. 以下是我构建的完整代码。 I would be grateful if anyone can help. 如果有人可以帮助,我将不胜感激。 Thanks! 谢谢!

ui.R 用户界面

library(shiny)

shinyUI(fluidPage(
titlePanel(""),
sidebarLayout(
sidebarPanel(
  fileInput("file", "Upload the file", 
            accept=c('text/csv', 'text/comma-separated-values,text/plain')),
  helpText("Default max. file size is 5MB"),
  tags$hr(style="padding:0px;margin:0px")
  ),

mainPanel(
tags$div(id = "main", dataTableOutput("dtt"), 
           style = "font-size:85%; position: absolute; left: 150px; width: 
1150px; top: 140px")),


tags$script(" $('#main').editable(function(value, settings) {
   console.log(this);
            console.log(value);
            console.log(settings);
            return(value);
}, {
            type    : 'text',
            indicator : 'Saving...',
            tooltip   : 'Click to edit...'
});") 


tags$head(tags$script(src="jquery.jeditable.js"))

)              
)
))

server.R 服务器

library(shiny)

shinyServer(function(input, output, session){

data <- reactive({
file1 <- input$file
if(is.null(file1)){return()}
df <- read.csv(file = file1$datapath, header = TRUE, fill = TRUE)
})


output$dtt <-renderDataTable(data(),
              extensions = 'Buttons',                    
              selection = "multiple",
              options = list(pageLength = 25, scrollX = TRUE, scrollY = 
'500px', 
                             dom = 'lBfrtip', buttons = 
                               list(list(
                                 extend = 'collection',
                                 buttons = c('csv', 'pdf'),
                                 text = 'Download'
                               ))
              ))

 })    

我所要做的就是在rstudios中更新我的DT r包,并附带了编辑功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM