Display specific information using cell edit

In the below application, I am using cell_edit to display the row, col and value I have edited. But there is some issue here. Whenever I enter values in rows, (The result shows 1,1,1,1,1,1,..... instead of just 1), Also if I enter values in Col 1 and Col 2, (the result shows 0, 1,2,3,4,.... instead of only 1 and 2), Also if I enter values as 12 in row1 and col1 and 6 in row1 and Col2, the result shows as "12" "6" "160" ..... and so on, instead of only "12" "5" .

So basically it the result shows all values. Can we make it so that the result shows accordingly.

library(shiny)

ui <- fluidPage(
  h2("Last edited:"),
  verbatimTextOutput("last_edited"),
  actionButton("reset", "Reset cell edited"),
  h2("Datatable:"),
  DT::dataTableOutput("dt")
)

server <- function(input, output) {

  # the last selected/clicked value
  output$last_edited <- renderPrint({
    str(input$dt_cell_edit)
  })

  output$dt <- DT::renderDataTable({
    DT::datatable(head(mtcars, 2), editable = 'row', rownames = F, selection = "none")
  })

  # observe the selected rows and do something after a new selection
  observeEvent(input$dt_cell_edit, {
    # validate(need(!is.null(input$dt_cell_edit), ''))
    print(input$dt_cell_edit$row)
    print(input$dt_cell_edit$col)
    print(input$dt_cell_edit$value)
  })

  myProxy = DT::dataTableProxy('dt')

  # reset last selected value
  observeEvent(input$reset, {
    DT::selectCells(myProxy, selected = NULL)
  })
}

shinyApp(ui, server)

it seems like you want to track the current and previous states of the tables so you can compare which values changed between them. When you edit the entire row, you edit the entire row... so if you want to see the changed colum values, you will need to do the compare yourself. so you should keep track of the past and present state also. Or switch from row edit to cell edit, so only one cell change at a time.

Thanks a lot for the help

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.