I have two data table which I want to download in two different sheets of an xlsx file after I have edited their cells. Using the below mentioned approach I am getting the error -
Warning: Error in : Assigned data cell$value
must be compatible with existing data.
i Error occurred for column Trial ID:
.
x Can't convert to .
[No stack trace available]
The relevant server code is as follows -
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)
}
)
Can someone please tell me where I am going wrong?