title: Shiny observeEvent expression runs more than once
body: <p>My observeEvent expression is being run twice when the action button is clicked once.</p>
  
  <p>Specifically, when the code below is run, if the "Add Item" button is clicked and then the first "Delete" button is clicked, the "deleted 1" message is printed twice. This is a minimal example of the behavior that I originally observed in a more complicated context.</p>
  
  <p>(In that more complicated example, the behavior of running multiple times was manifesting as all items being deleted when one delete button was clicked. I determined that it was because the delete logic to remove an item at a particular index was running multiple times.)</p>
  
  <pre><code>library(plyr)
  library(shiny)
  
  ui &lt;- fluidPage(
    actionButton("addItem", "Add Item"),
    uiOutput("items")
  )
  
  server &lt;- function(input, output, session) {
    itemsReactive &lt;- reactiveVal(list(Item1 = "foo"))
    observeEvent(input$addItem, {
      itemsReactive(c(itemsReactive(), list(Item2 = "foo")))
    })
    output$items &lt;- renderUI({
      splat(div)(
        unname(mapply(function(item, index) {
          deleteButtonId &lt;- paste('delete-button', index, sep = '-')
          observer &lt;- observeEvent(input[[deleteButtonId]], {
            print(paste("deleted", index))
            observer$destroy()
          }, once = TRUE)
          div(actionButton(deleteButtonId, "Delete"))
        }, itemsReactive(), seq_along(itemsReactive()), SIMPLIFY = FALSE))
      )
    })
  }
  
  shinyApp(ui = ui, server = server)
  </code></pre>
  
  <p>Why does the print statement run more than once when the delete button is only clicked once? How can this be fixed?</p>
  
  <p>Originally, I did not have the <code>observer$destroy()</code> nor the <code>once = TRUE</code>. These were added each in an attempt to stop the code from running multiple times.</p>
  
  <p>My package versions:</p>
  
  <pre><code>other attached packages:
  [1] plyr_1.8.4  shiny_1.2.0
  </code></pre>