inst/examples/loadingButton_tests/server.R

server <- function(input, output, session) {
  
  n_loading_buttons <- 0
  
  observeEvent(input$insert, {
    
    id_ <- paste0('insert_btn_', n_loading_buttons)
    
    insertUI(
      selector = "#insert",
      where = "afterEnd",
      ui = tagList(
        loadingButton(
          id_,
          'Insert Button'
        )
      )
    )
    
    n_loading_buttons <<- n_loading_buttons + 1
    
    observeEvent(input[[id_]], {
      Sys.sleep(2)
      resetLoadingButton(id_)
    })
    
  })
  
  observeEvent(input$remove, {
    
    id_ <- paste0('#insert_btn_', n_loading_buttons - 1)
    
    removeUI(
      selector = id_
    )
    
    n_loading_buttons <<- n_loading_buttons - 1
    
    # observeEvent(input[[id_]], {
    #   Sys.sleep(2)
    #   resetLoadingButton(id_)
    # })
    
  })
  
  observeEvent(input$btn, {
    Sys.sleep(2)
    resetLoadingButton("btn")
  })
  
}

# secure_server(server)

Try the shinyFeedback package in your browser

Any scripts or data that you put into this service are public.

shinyFeedback documentation built on Sept. 24, 2021, 5:07 p.m.