我有两个数据表,在我编辑了它们的单元格后,我想将它们下载到 xlsx 文件的两个不同表中。使用下面提到的方法我得到了错误 -
警告:错误:分配的数据cell$value
必须与现有数据兼容。i 列发生错误Trial ID:
。x 无法转换为 . [没有可用的堆栈跟踪]
相关服务器代码如下——
x<- reactive({
inFile <- input$file
if(is.null(inFile))
return(NULL)
file.rename(inFile$datapath,
paste(inFile$datapath, ".xlsx", sep=""))
read_excel(paste(inFile$datapath, ".xlsx", sep=""),sheet = 1)
})
y <- reactive({
inFile <- input$file
if(is.null(inFile))
return(NULL)
file.rename(inFile$datapath,
paste(inFile$datapath, ".xlsx", sep=""))
read_excel(paste(inFile$datapath, ".xlsx", sep=""),sheet = 2)
})
output$table1 <- renderDataTable({
x()
}, filter="top", class = 'hover cell-border stripe', editable= TRUE,extensions= 'Buttons',
options = list(dom = 'Bfrtip',pageLength =10,
buttons = c('copy','csv','excel','pdf','print'), scrollX=TRUE),server=FALSE)
output$table2 <- renderDataTable({
y()
}, filter="top", class = 'hover cell-border stripe', editable= TRUE,extensions= 'Buttons',
options = list(dom = 'Bfrtip',pageLength =10,
buttons = c('copy','csv','excel','pdf','print'), scrollX=TRUE),server=FALSE)
observeEvent(input[["table1_cell_edit"]], {
cell <- input[["table1_cell_edit"]]
newdf <- x()
newdf[cell$row, cell$col] <- cell$value
x(newdf)
})
observeEvent(input[["table2_cell_edit"]], {
cell <- input[["table2_cell_edit"]]
newdf <- y()
newdf[cell$row, cell$col] <- cell$value
y(newdf)
})
output$dl <- downloadHandler(
filename = "test.xlsx",
content = function(file) {
write.xlsx2(x(), file, sheetName = "Sheet1")
write.xlsx2(y(), file, sheetName = "Sheet2", append = TRUE)
}
)
有人可以告诉我哪里出错了吗?