r - 具有持久数据表的可编辑闪亮 DT 不显示过滤记录
问题描述
什么不正常:在过滤数据时,当我编辑一些值时,它会显示“未找到匹配的记录”。理想情况下,我应该能够对过滤后的数据进行编辑,并且记录应该保持存在。 编辑时不过滤;然后它工作正常。但是在对过滤后的数据进行编辑时,它不起作用。 下面我附上了截图以使其更清晰。谢谢。
library(shiny) # v. 1.2.0
library(DT) # v. 0.5
#page_length <- 2 # 5 elements should span 3 pages
hardcoded_df <- read.table(text = "Fruit Color
Apple Red
Plum Purple
Blueberry Duh
Orange Carrot
Crocodile Green
Grapes Green",
header = TRUE,
stringsAsFactors = FALSE)
ui <- fluidPage(
DT::dataTableOutput('x1')
)
server <- function(input, output, session) {
x <<- reactiveValues()
x$df <<- hardcoded_df
DT=isolate(x$df)
#Code to convert Factor
DT <- as.data.frame(unclass(DT))
output$x1 = DT::renderDataTable(datatable(DT, plugins = "ellipsis",
class = 'white-space: nowrap',
filter = list(position = 'top', clear = TRUE, plain = TRUE) ,
extensions = c('Buttons','AutoFill','FixedHeader', 'KeyTable','ColReorder'), editable = list(
target = 'cell'
), selection = "single",escape = FALSE ,
options = list(
keys = TRUE, colReorder = list(realtime = FALSE),
fixedHeader = TRUE, autoFill = list(focus = 'click', horizontal = FALSE) ,
autoWidth=TRUE, pageLength = 2 ,editable = TRUE,
lengthMenu = list(c(2, 50, -1), c('2', '50', 'All')), dom = 'lBfrtip',buttons = list(
c('colvis','pdf','excel'),
list(
extend = "collection",
text = 'Show All',
action = DT::JS("function ( e, dt, node, config ) { dt.page.len(-1);
dt.ajax.reload();
}"))))
))
proxy = dataTableProxy('x1')
data = reactiveValues()
observeEvent(input$x1_cell_edit, {
info = input$x1_cell_edit
str(info)
# str(input$x1_state)
i = info$row
j = info$col
v = info$value
View(x$df)
# Without this line the table does not change but with it it jumps to row 1 after an edit.
x$df[i, j] <- (DT::coerceValue(v, x$df[i, j]))
DT::replaceData(proxy, x$df, resetPaging = FALSE) # important
# Now we need to scroll to row i somehow ... clearly this does not work. Help!
#selectPage(proxy, ceiling(i / page_length))
# selectRow(proxy, i)
})
}
shinyApp(ui = ui, server = server)
解决方案
推荐阅读
- javascript - window.XMLHttpRequest 的含义?(阿贾克斯)
- docker - 无法创建目录“/home/jenkins/.m2”:权限被拒绝
- javascript - 为什么我们可以在浏览器中使用全局变量?
- ant - Ant junitlauncher 任务不运行测试
- ajax - 在 laravel 中使用 ajax 调用并获取 document.execCommand("copy") 但它不起作用
- laravel - 如何将数据从部分页面传递到主要的 laravel 母版页?
- mysql - 从满足的状态和数据库查询中的 id 获取间隔 1 天的日期
- mysql - 为什么查询中没有提到任何命名列时会出现新列错误?
- java - 如何检查类型化类的类型
- mysql - 需要在不同的域中部署相同的 Codeigniter 代码,但使用不同的数据库