Alerts in Chrome and IE

The sendSweetAlert function from the shinyWidgets package is a great way to communicate behavior to an end-user. As of version 0.4.9 shinyWidgets now uses SweetAlert2 which is no longer compatible with Internet Explorer thus breaking historical apps which use this feature. This is due to the fact that IE does not support arrow functions.
One workaround is to switch from using sweetalert to using shiny's built in showNotification function. This function works under both Chrome and IE but is not as customizable or beautiful as sweetalert. Another alternative is to identify the browser and provide a sweetalert if running Chrome or shiny notification if not. This is achieved by using javascript to assign a shiny INPUT (input$chrome) variable and using this value to determine whch type of notification to show.

Included in UI

1tags$script(HTML(
2      '$(document).on("shiny:sessioninitialized", function(event) {
3      var runningChrome = /Chrome/.test(navigator.userAgent);
4      Shiny.setInputValue("chrome", runningChrome);
5    });'

Included in server

 1show_alert <- function(session = getDefaultReactiveDomain(), chrome_browser = FALSE, title = NULL, text = NULL, type = 'error', btn_labels = NULL) {
 2  if (!type %in% c('info', 'success', 'warning', 'error')) type <- 'info'
 3  if (chrome_browser) {
 4    if (!is.null(btn_labels)) {
 5      sendSweetAlert(session = session, title = title, text = text, type = type, btn_labels = btn_labels, closeOnClickOutside = TRUE)
 6    } else {
 7      sendSweetAlert(session = session, title = title, text = text, type = type, closeOnClickOutside = TRUE)
 8    }
 9  } else {
10    text <- str_replace(text, '\\n', '<br>')
11    if (type == 'info') type <- 'default'
12    if (type == 'success') type <- 'message'
13    showNotification(session = session, ui = title, action = HTML(text), type = type)
14  }
15}

The show_alert function takes a session variable, chrome_browser logical and some additional pararmeters to build a notification.