I was trying to find a way to show my simulation result iteratively in Shiny and want to have a button to reset everything. It took me a while to figure this out and its not complicated! You can do many things based on my example. Enjoy!

shinyUI

Now we begin to build our shinyapp. A shinyapp is made of two parts, the “shinyUI” part and the “shinyServer” part. The “shinyUI” part is for input, and the “shinyServer” part is for output.

library(shiny)
library(ggplot2)
ui <- fluidPage(
   
   titlePanel("Iteratively showing result and Reset Everything"),
   
   sidebarLayout(
      sidebarPanel(
        
        h6("Press to show next result"),
        actionButton("nextsim", "Next"), 
        verbatimTextOutput("value_next"),
        hr(),
        
        h6("Press to show all result"),
        actionButton("go", "All"), 
        verbatimTextOutput("value_all"),
        hr(),
        
        h6("Press to Reset"),
        actionButton("reset1", "Reset")
      ),
      
      mainPanel(
        plotOutput("distPlot")
      )
   )
)

ShinyServer

The “ShinyServer” part controls the output of shinyapp.

server <- function(input, output) {
  
  # It's not a good idea to change the input value
  # you need some interactive values to be changed or reset
  values <- reactiveValues(
    data_next = 0,
    data_all = 0
  )
  
  # showing the value
  output$value_next <- renderPrint({ cat(paste0(" input$nextsim ", input$nextsim),"\n",
                                    paste0("values$data_next ", values$data_next),"\n")})
  # showing the value
  output$value_all <- renderPrint({ cat(paste0("input$go ", input$go), "\n",
                                        paste0("values$data_all ", values$data_all),"\n")})
  
  # data I want to plot
  data <- data.frame( x= 0:10, y = (0:10)^2 )
  
  # plot result iteratively when you press "Next"
  resultplot_next <- eventReactive(input$nextsim, {
      
        # change the value "data_next" when you press "Next"
        values$data_next <- values$data_next + 1

        # plot partial data
        subdata <- data[1:values$data_next,]
      
        p1 <-ggplot(subdata, aes(x,y)) + geom_point() + geom_line()+
          xlim(c(0,10)) + ylim(c(0,100))
        
        print(p1)
  })
  
  # plot all result when you press "All"
  resultplot_all <- eventReactive(input$go, {
    
    # plot all data
    subdata <- data
    
    p1 <-ggplot(subdata, aes(x,y)) + geom_point() + geom_line()+
      xlim(c(0,10)) + ylim(c(0,100)) 
    
    print(p1)
  })
  
      output$distPlot <- renderPlot({
        
        # If you press "Next", show the next result. If you press "All", show all result
        if ( values$data_all == 0 ){
          resultplot_next()
        } else {
          resultplot_all()
        }
      })
      
      observeEvent(input$go, {
        # change the value "data_next" when you press "All"
        values$data_all <- values$data_all + 1
      })  
      
      observeEvent(input$reset1, {
        # Reset data_next and data_all to 0
        values$data_next <-  0
        values$data_all <- 0
      })  
      
}

# Run the application 
shinyApp(ui = ui, server = server)