I am developing an app where I display a (large) Markov transition matrix as a datatable, rendered client side. Of course, we can make this transition matrix editable for the user.
I would like to be able to:
- after the user edits some cells and then clicks an update button,
- to capture all values in all cells of this newly edited datatable (which was edited client side), and return it to R, say, as a matrix
I would then use these values to update a server side matrix/dataframe to now be these new values.
Here is a sample shiny app that might implement this:
library(DT)
library(shiny)
ui <- function(input, output, session) {
fluidPage(
textOutput('edit'),
DTOutput('test'),
actionButton('actbut', label = 'click')
)
}
server <- function(input, output, session) {
rv <- reactiveValues( df = iris )
output[['test']] <- renderDT({
datatable(rv$df, editable = T)
}, server = F)
observeEvent(input$actbut, {
# -- Suppose the user manually changes
# --all entries in df in the
# --Species column to "setosa", clientside.
# -- I would like to be able to access the newly changed entries
# -- using some attribute of input$test_<something>;
# -- in the same vein of input$test_cell_clicked, etc.
})
}
shinyApp(ui = ui, server = server, options = list(port = 5858))
If there is already an easy way to do this, please let me know.
Thanks to Yihui Xie for an incredible library.