Learn R Programming

shinyBS (version 0.20)

createAlert: Twitter Bootstrap Alerts

Description

Functions to add and remove Twitter Bootstrap alerts in Shiny

Usage

bsAlert(inputId)

createAlert(session, inputId, alertId = NULL, title = NULL, message = NULL, 
            type = NULL, dismiss = TRUE, block = NULL, append = TRUE)
            
closeAlert(session, alertId)

Arguments

session
The session object passed to function given to shinyServer
inputId
Id of alert anchor to create alert in
alertId
An id for the created alert. Optional, but necessary if you want to close it later with closeAlert
title
A title for the alert. This text will be at the top of the alert and be in larger, bold font
message
The main text of the alert
type
One of four options: warning, danger, info, or /code{success}
dismiss
Should the user be able to dismiss the alert? logical
block
Should block formatting be applied to the alert? logical
append
Should the alert be added below other alerts already in the alert anchor (TRUE), or should it replace and already existing alerts (FALSE)

Details

By default each new alert will be added below any previously existing alerts. If you want only one alert to appear at a time change append to FALSE. This will cause new alerts to overwrite any previously existing alerts. Block style is an option discussed in the Twitter Bootstrap documentation, though it doesn't make any difference that the author can see.

References

http://getbootstrap.com/2.3.2/components.html{Alerts for Twitter Bootstrap 2.3.2}

Examples

Run this code
## In ui.R
  ## Create an alert anchor:
  bsAlert(inputId="aa")
  
  ## In server.R
  ## Add an alert to the previously created alert anchor:
  createAlert(inputId = "aa", alertId="a1", 
              title = "Oops!", 
              message="Something isn't right, please recheck your inputs.",
              type = "danger")
  ## Close the alert programatically
  closeAlert(session, alertId = "a1")

Run the code above in your browser using DataLab