Is it possible to have multiple users modifying the same DT table simultaneously (like a google doc / excel ...) ? We have an app with a table where users that are connected to the app need to add comments within the table. But in the case of multiple users that have loaded the page before anyone has added a comment, the last one to add one deletes all previously entered comments. I've done this kind of thing with a MongoDB but for this app we would like to stay inside shiny. Would you know how to circumvent this issue ? If Shiny package exists, even if it's not DT related ? Thanks a lot, let me know if I can clarify the question !!
This can be done using a global reactiveVal
(defined outside of the server
function), which is shared among sessions.
The following is based on the example given here:
library(shiny)
library(DT)
DF <- reactiveVal(iris) # cross session reactiveVal
ui <- fluidPage(DTOutput('myTable'))
server <- function(input, output, session) {
observeEvent(input$myTable_cell_edit, {
info = input$myTable_cell_edit
str(info)
i = info$row
j = info$col + 1 # column index offset by 1
v = info$value
tmpDF <- DF()
tmpDF[i, j] <- DT::coerceValue(v, DF()[i, j])
DF(tmpDF)
})
output$myTable <- renderDT({
DF()
}, selection = 'none', rownames = FALSE, editable = TRUE)
}
shinyApp(ui, server)
DT edit in the first session appears in the second and vice versa: