闪亮:使编辑在可编辑数据表中跨页面持续存在
Shiny : Make edits persist across pages in editable datatable
我有一个可编辑的数据表,其分页如下:
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"
)
当我在当前页面上进行编辑时,移动到其他页面,然后 return 到上一页时,我在该页面上所做的编辑消失了。我怎样才能让编辑在页面上持久化?
以下是我用来观察编辑的代码-
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
})
您必须使用代理和 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)
我有一个可编辑的数据表,其分页如下:
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"
)
当我在当前页面上进行编辑时,移动到其他页面,然后 return 到上一页时,我在该页面上所做的编辑消失了。我怎样才能让编辑在页面上持久化?
以下是我用来观察编辑的代码-
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
})
您必须使用代理和 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)