Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix both bugs in #31 #32

Closed
wants to merge 5 commits into from
Closed

Fix both bugs in #31 #32

wants to merge 5 commits into from

Conversation

dipterix
Copy link

@dipterix dipterix commented Jul 8, 2020

See #31 and #29

Commit e8c393d added closeAlert and immediate requested by #29 and #30. It automatically fixes bug2 in #31

Commit 66b430e fixed two js bugs and allows closeAlert to close a specific alert

Commit 839117e fixes all bugs in #31

@dipterix
Copy link
Author

dipterix commented Jul 8, 2020

Demo examples

library(shiny)
library(shinyalert)

ui <- fluidPage(
  shinyalert::useShinyalert(),
  actionButton('a','Timer works when multiple alerts are queued'),
  actionButton('b','Immediate = TRUE'),
  actionButton('c','callbackR close alerts automatically'),
  actionButton('d','3 alerts, but the third alert only closes the first one'),
  actionButton('e','3 alerts, once the first one closes, the second alert closes too'),
  actionButton('f','Alert within callbackR')
)

server <- function(input, output, session) {
  # ----- Timer works when multiple alerts are queued ------
  observeEvent(input$a, {
    shinyalert::shinyalert(
      'This alert close automatically',
      'Wait...',
      timer = 3000,
      showConfirmButton = FALSE
    )
    shinyalert::shinyalert(
      'Yay',
      ' '
    )
  })
  
  # ----- Immediate = TRUE ------
  observeEvent(input$b, {
    shinyalert::shinyalert(
      'Test the following case',
      '<pre>Immediate = TRUE</pre>',
      closeOnClickOutside = FALSE,
      showConfirmButton = FALSE,
      html = TRUE
    )
    Sys.sleep(2)
    shinyalert::shinyalert(
      'Auto close the first one!',
      '', timer = 3000, immediate = TRUE
    )
  })
  
  # ----- callbackR close alerts automatically ------
  observeEvent(input$c, {
    shinyalert::shinyalert(
      'Warning',
      'Click OK to run code',closeOnClickOutside = TRUE,
      callbackR = function(...){
        # procedure 1 runs for 3~4 seconds
        Sys.sleep(3 + runif(1))
        # Now dismiss modal
        shinyalert::closeAlert(2)
      }
    )
    shinyalert::shinyalert(
      'Scheduled!',
      'R is running, please wait for the result...',
      showConfirmButton = FALSE
    )
  })
  # ----- 3 alerts, but the third alert only closes the first one -----
  shiny::observeEvent(input$d, {
    cbid_a <- shinyalert::shinyalert(
      'This is alert A',
      'It automatically closes once C is queued',
      showConfirmButton = FALSE
    )
    shinyalert::shinyalert(
      'This is alert B',
      'C only closes A but not B',
      callbackR = function(...){
        Sys.sleep(3)
        shinyalert::closeAlert()
      }
    )
    Sys.sleep(2)
    shinyalert::shinyalert(
      'This is alert C',
      'Wait for callback (B) to finish',
      showConfirmButton = FALSE
    )
    shinyalert::closeAlert(cbid = cbid_a)
  })
  
  # ----- 3 alerts, once the first one closes, the second alert closes too -----
  shiny::observeEvent(input$e, {
    shinyalert::shinyalert(
      'This is alert A',
      'Close A will also close B',
      callbackR = function(...){
        # close one alert, which is B
        closeAlert(n = 1)
      }
    )
    shinyalert::shinyalert(
      'This is alert B',
      'You might be unable to see me'
    )
    shinyalert::shinyalert(
      'This is alert C',
      'A, B are closed, only me left'
    )
  })
  
  # ----- Alert within callbackR -----
  observeEvent(input$f, {
    shinyalert::shinyalert(
      "modal 1",
      timer = 1000,
      callbackR = function() {
        shinyalert::shinyalert("modal 2")
      })
  })
}


shinyApp(ui, server)

@daattali
Copy link
Owner

These two JS bugs can be fixed independently of the closeAlert PR, right? This PR should only contain the code to fix those two js issues, nothing else :)

@daattali
Copy link
Owner

daattali commented Sep 9, 2020

Merged in #37

@daattali daattali closed this Sep 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants