I'm developing a shiny app which is reading data from SQL database and present it in a rhandsontable and allows user to edit the data. I would like to add some functionality before I submit the changes back to the database :
- How could I highlight a row in rhandsontable if a cell in that row was edited ?
- Is there a way to collect all the changes / edits on the table,
since the
input$myTable$changes$changes
just shows the last changes !
here is my minimal sample code:
df <- structure(list(NumberOfWEC = c(3, 4, 54, 19, 10, 6, 8, 11, 140,
11, 34), Source = c("SRP", "SRP", "SRP", "SRP", "SRP", "RBP",
"SRP", "SRP", "SRP", "SRP", "SRP"), Status = structure(c(3L,
3L, 2L, 3L, 2L, 1L, 2L, 1L, 2L, 2L, 2L), .Label = c("CANDIDATE",
"APPROVED", "EXISTING"), class = c("ordered", "factor"))), row.names = c(NA,
11L), class = "data.frame")
ui <- fluidPage(
rHandsontableOutput("myTable")
)
server <- function(input, output, session) {
ColNames <- (colnames(df))
ColNames <- ColNames[!ColNames %in% "Status"]
output$myTable <- renderRHandsontable({rhandsontable(df) %>% hot_col(ColNames, readOnly = TRUE)})
observeEvent(input$myTable$changes$changes, {
changedRow = 1 + as.numeric(input$myTable$changes$changes[[1]][[1]])
changedColl = 1 + as.numeric(input$myTable$changes$changes[[1]][[2]])
OldValue = input$myTable$changes$changes[[1]][[3]]
NewValue = input$myTable$changes$changes[[1]][[4]]
print(paste0("changedRow = ",changedRow, " changedColl = ", changedColl, " OldValue = ", OldValue, " NewValue = ", NewValue, " by = ",session$user))
})
}
shinyApp(ui, server)