Hi,
I am using the new editable function in DT tables and am wondering if it is possible to undo an edit if it fails validation?
I have managed to get an error message to pop up if there is a problem, but can't seem to figure out how to undo the actual edit in the webpage. For example in the below app, filling a numeric cell with string will cause the error modal message to show, but after closing the error modal the string is still in the table, not the original value
Any suggestions on what I might be missing?
Thanks
Iain
library(shiny)
library(DT)
shinyApp(
ui = fluidPage(
DTOutput('x1'),
verbatimTextOutput("print")
),
server = function(input, output, session) {
x = reactiveValues(df = NULL)
observe({
df <- iris
df$Date = Sys.time() + seq_len(nrow(df))
x$df <- df
})
output$x1 = renderDT(x$df, selection = 'none', editable = TRUE)
proxy = dataTableProxy('x1')
observeEvent(input$x1_cell_edit, {
info = input$x1_cell_edit
str(info)
i = info$row
j = info$col
v = info$value
update_value<-isolate(DT::coerceValue(v, x$df[i, j]))
if(!is.na(update_value)){
x$df[i, j] <- update_value
}else{
showModal(modalDialog(
title = "Validation error",
"The value didn't validate"
))
# reseting to old value doesn't seem to work
v<-input$x1_cell_clicked$value
x$df[i, j] <- isolate(DT::coerceValue(v, x$df[i, j]))
}
})
}
)