ebailey78 / shinyBS

Twitter Bootstrap Components for Shiny
182 stars 47 forks source link

alert timeout #67

Open jonkatz2 opened 8 years ago

jonkatz2 commented 8 years ago

Hi, I'm using shinyBS alerts and tooltips, they are really great and simple to use. One thing I've been doing is adding a timeout to my alerts, then I can use an alert to notify users that an observer completed an invisible task, such as saving a table to a folder that will later be zipped for download.

Here's how I did it: 1) I added a "timeout" argument to createAlert() that takes a numeric value in milliseconds:

createAlert <- function (session, anchorId, alertId = NULL, title = NULL, content = NULL, 
    style = NULL, dismiss = TRUE, append = TRUE, timeout = NULL) 
{
    data <- dropNulls(list(id = anchorId, alertId = alertId, 
        title = title, content = content, style = style, dismiss = dismiss, 
        append = append, timeout = timeout))
    session$sendCustomMessage(type = "bsAlertCreate", data)
}

2) In shinyBS.js I added to the customMessageHandler "bsAlertCreate" :

if(data.hasOwnProperty('timeout')) {
    window.setTimeout(function() {
        $alert.fadeTo(500, 0).slideUp(500, function(){
             $alert.close(); 
        });
    }, data.timeout)
}

I only use it with append=FALSE, I don't know if it works with append=TRUE. This is is mostly adapted from http://stackoverflow.com/questions/7643308/how-to-automatically-close-alerts-using-twitter-bootstrap