输入更新后编辑闪亮数据表中的数据

时间:2020-07-16 05:14:15

标签: r shiny save edit dt

我在Shiny中创建了一个数据表,第一列可编辑。我可以输入文本,但是在切换输入值然后返回后它们会消失。例如,我为“男性高级BladeRazor系统”的类别输入了“ testing 001”,一切似乎都很好(参见图片)。但是,在将我的类别切换到另一个值然后返回到“ Male Premium BladeRazor系统”后,输入的“测试001”文本将消失。我的代码很长,因此我将其中的一部分切掉以供参考。任何帮助将不胜感激。谢谢。 Example of text edits

    output$tabofrandom <- DT::renderDataTable(
       if (is.null(names(tab7data$dat))) {
      datatable(tab7data$dat)
     } 
      else {
       datatable(isolate(tab7data$dat),
              editable = list(target = 'cell', disable = list(columns = c(1,2, 3, 4,5,6,7,8,9))),
              rownames = FALSE, 
              selection = list(mode = "single", target = "row", selected = previousSelection),
              extensions = c('Buttons'),
              options = list(searching=FALSE, 
                             scrollX=T,
                             scrollY=277,
                             #processing=FALSE,
                             autoWidth = TRUE,
                             displayStart = previousPage,
                             dom = 'Blfrtip',
                             #  pageLength = 5, 
                             lengthChange = FALSE,
                             lengthMenu = list(c(5,10, -1), c("5","10", "All")),
                             buttons = list(c('pageLength','excel'),list(extend = 'colvis')),
                             # buttons = c('excel','colvis'),
                             columnDefs=list(list(targets=c(2,4,5,8), 
                                                  render = JS("function(data){return data.replace(/;/g, 
         '<br>');}")),
                                         ...
                             ))
      )  %>%
       formatStyle(1:10, 'text-align' = 'left') %>%
      formatStyle(1:10, 'vertical-align'='top') 
     } )

   ...
   observeEvent(input[["tabofrandom_cell_edit"]], {
   info <- input[["tabofrandom_cell_edit"]]
   info$col=info$col+1
   previousSelection <<- input$tabofrandom_rows_selected
   previousPage <<- input$tabofrandom_rows_current[1] - 1
   tab7data$dat<-isolate(DT::editData(tab7data$dat,info))
   })
   ...

1 个答案:

答案 0 :(得分:0)

您必须将server的{​​{1}}选项设置为renderDataTable或使用代理:

FALSE

您不必为proxy <- DT::dataTableProxy("tabofrandom") observeEvent(input[["tabofrandom_cell_edit"]], { info <- input[["tabofrandom_cell_edit"]] ...... tab7data$dat <- DT::editData(tab7data$dat, info, proxy) }) info$col + 1