title: Add and delete rows of DT Datatable in R Shiny
body: <p>I'm trying to add a "save inputs" feature to my Shiny app where the saved inputs would be saved in a DT data table. If a user clicks an <strong>Add</strong> button, the inputs would be appended to a data table. A user then can delete a row from this data table by selecting a row and clicking the <strong>Delete</strong> button. I also need to have this table's values be saved as a global variable so it stays persistent across all sessions.</p>
  
  <p>The example code is shown below. When I close the session, the table (<code>this_table</code>) is correctly updated, however, those changes don't appear realtime during the app. I've tried putting both of these input buttons in an <code>eventReactive</code> function, but this did not work when one of the buttons was selected more than once.</p>
  
  <p>Any ideas?</p>
  
  <p>Global table:</p>
  
  <p><code>this_table = data.frame(bins = c(30, 50), cb = c(T, F))</code></p>
  
  <p>Shiny app code:</p>
  
  <pre><code>ui &lt;- fluidPage(
  
     sidebarLayout(
        sidebarPanel(
           sliderInput("bins",
                       "Number of bins:",
                       min = 1,
                       max = 50,
                       value = 30),
           checkboxInput("cb", "T/F"),
           actionButton("add_btn", "Add"),
           actionButton("delete_btn", "Delete")
        ),
  
        mainPanel(
           DTOutput("shiny_table")
        )
     )
  )
  
  server &lt;- function(input, output) {
  
  
    observeEvent(input$add_btn, {
      t = rbind(data.frame(bins = input$bins,
                           cb = input$cb), this_table)
      this_table &lt;&lt;- t
    })
  
    observeEvent(input$delete_btn, {
      t = this_table
      print(nrow(t))
      if (!is.null(input$shiny_table_rows_selected)) {
        t &lt;- t[-as.numeric(input$shiny_table_rows_selected),]
      }
      this_table &lt;&lt;- t
    })
  
    output$shiny_table &lt;- renderDT({
     datatable(this_table, selection = 'single', options = list(dom = 't'))
    })
  }
  
  shinyApp(ui = ui, server = server)
  </code></pre>