0

I am trying to edit data table and update the records post row editing on click of action button "Update Table". How to retrive/display new Data table records reactively post modifying fields in existing Data table record?

library(shiny)
library(shinyjs)
library(DT)
library(data.table)

mydata = data.frame(id=letters[1:5], val=sample(10,5,T))
lengthofData <- nrow(mydata)
mydata[["Constraint Type"]] <-  c(">")
))

mydata[["Constraint Value"]] <- c(1)

ui = fluidPage(dataTableOutput("table"),
               actionButton("goButton", "Update Table"),
               dataTableOutput("newtable"))

server = function(input,output){

  x <- mydata
  output$table <- renderDataTable( x,server = FALSE,
                                   escape = FALSE,
                                   selection = 'none')

  proxy = dataTableProxy('table')

  xNew<-reactiveValues()

  observeEvent(input$x1_cell_edit, {
    info = input$x1_cell_edit
    str(info)
    i = info$row
    j = info$col + 1
    v = info$value
    x[i, j] <<- DT:::coerceValue(v, x[i, j])
    replaceData(proxy, x, resetPaging = FALSE, rownames = FALSE)
    xNew<<-x
  })

  observeEvent(input$goButton,{
    output$newtable <- renderDataTable( xNew(),server = FALSE,
                                     escape = FALSE,
                                     selection = 'none')

  })

}

shinyApp(ui,server)
  • This looks like three separate questions. I think multipart questions are discouraged on SO. https://meta.stackoverflow.com/questions/275908/more-than-one-question-per-post – IRTFM Dec 28 '17 at 19:33
  • Modified the above query and removed other multiple questions. Thanks for the information – shailesh kumar Dec 28 '17 at 19:37
  • 2
    maybe use `rhandsontable()` and its documentation to accomplish this? – InfiniteFlash Dec 28 '17 at 19:57
  • looks like a duplicate Q. Check this https://stackoverflow.com/questions/27636931/how-to-implement-inline-editing-on-datatables-in-r-shiny – user5249203 Dec 28 '17 at 19:59
  • Possible duplicate of [How to implement inline editing on datatables in R Shiny](https://stackoverflow.com/questions/27636931/how-to-implement-inline-editing-on-datatables-in-r-shiny) – Kevin Arseneau Dec 29 '17 at 02:11
  • `DT` has an experimental live editor feature branch you could use - check out https://stackoverflow.com/questions/47463533/r-shiny-how-to-change-stored-data/47523671#47523671 for an example – greg L Dec 29 '17 at 02:25
  • Why is `library(data.table)` loaded? It seems you don't use any `data.table` (advanced data.frame) syntax. Perhaps, a mix-up with *Data Table* (`library(data.table)`)? – Uwe Dec 31 '17 at 15:46

0 Answers0