【问题标题】:Shiny : Make edits persist across pages in editable datatableShiny : 使编辑在可编辑数据表中的页面之间持续存在
【发布时间】:2020-10-21 16:58:07
【问题描述】:

我有一个可编辑的数据表,分页如下:

d1 = file.df
output$file.df_data<-DT::renderDataTable(
      d1,selection = 'none', editable = list(target = "cell", disable = list(columns = c(which(names(d1) != "product_type")-1))), 
      rownames = FALSE,
      extensions = 'Buttons',
      
      options = list(
        paging = TRUE,
        searching = TRUE,
        fixedColumns = TRUE,
        autoWidth = TRUE,
        ordering = TRUE,
        dom = 'Bfrtip',
        buttons = c('csv', 'excel')
      ),
      
      class = "display"
    )

当我在当前页面上进行编辑时,移动到其他页面,然后返回上一页,我在该页面上所做的编辑就会消失。我怎样才能使编辑在页面中保持不变?

以下是我用来观察编辑的代码-

observeEvent(input$file.df_data_cell_edit, {
      d1[input$file.df_data_cell_edit$row,input$file.df_data_cell_edit$col+1] <<- input$file.df_data_cell_edit$value
    })

【问题讨论】:

    标签: r shiny dt shinyapps


    【解决方案1】:

    您必须使用代理和editData 函数:

    library(shiny)
    library(DT)
    
    ui <- basicPage(
      br(),
      DTOutput("dtable")
    )
    
    server <- function(input, output, session){
      
      dat <- iris
      
      output[["dtable"]] <- renderDT({
        datatable(dat, editable = TRUE)
      })
      
      proxy <- dataTableProxy("dtable")
      
      observeEvent(input[["dtable_cell_edit"]], {
        info <- input[["dtable_cell_edit"]]
        dat <<- editData(dat, info, proxy)
      })
      
    }
    
    shinyApp(ui, server)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-08
      • 1970-01-01
      • 1970-01-01
      • 2020-09-14
      • 1970-01-01
      • 2020-06-17
      相关资源
      最近更新 更多