Title: | Notifications from 'Shiny' |
---|---|
Description: | Browser notifications in 'Shiny' apps, using 'toastr': <https://github.com/CodeSeven/toastr#readme>. |
Authors: | John Papa, Tim Ferrell, Hans Fjällemark, Gábor Csárdi |
Maintainer: | Gábor Csárdi <[email protected]> |
License: | MIT + file LICENSE |
Version: | 2.2.0.9000 |
Built: | 2024-12-23 02:58:42 UTC |
Source: | https://github.com/gaborcsardi/shinytoastr |
Remove existing toastr notifications
toastr_clear_all(with_animation = FALSE)
toastr_clear_all(with_animation = FALSE)
with_animation |
If |
There are four functions to create notifications:
toastr_success
, toastr_info
, toastr_warning
and
toastr_error
. They have exactly the same arguments and API
in general, but they create different kinds of notifications, styled
appropriately.
toastr_success(message, title = "", closeButton = FALSE, newestOnTop = FALSE, progressBar = FALSE, position = c("top-right", "top-center", "top-left", "top-full-width", "bottom-right", "bottom-center", "bottom-left", "bottom-full-width"), preventDuplicates = FALSE, showDuration = 300, hideDuration = 1000, timeOut = 5000, extendedTimeOut = 1000, showEasing = c("swing", "linear"), hideEasing = c("swing", "linear"), showMethod = c("fadeIn", "slideDown", "show"), hideMethod = c("fadeOut", "hide")) toastr_info(message, title = "", closeButton = FALSE, newestOnTop = FALSE, progressBar = FALSE, position = c("top-right", "top-center", "top-left", "top-full-width", "bottom-right", "bottom-center", "bottom-left", "bottom-full-width"), preventDuplicates = FALSE, showDuration = 300, hideDuration = 1000, timeOut = 5000, extendedTimeOut = 1000, showEasing = c("swing", "linear"), hideEasing = c("swing", "linear"), showMethod = c("fadeIn", "slideDown", "show"), hideMethod = c("fadeOut", "hide")) toastr_warning(message, title = "", closeButton = FALSE, newestOnTop = FALSE, progressBar = FALSE, position = c("top-right", "top-center", "top-left", "top-full-width", "bottom-right", "bottom-center", "bottom-left", "bottom-full-width"), preventDuplicates = FALSE, showDuration = 300, hideDuration = 1000, timeOut = 5000, extendedTimeOut = 1000, showEasing = c("swing", "linear"), hideEasing = c("swing", "linear"), showMethod = c("fadeIn", "slideDown", "show"), hideMethod = c("fadeOut", "hide")) toastr_error(message, title = "", closeButton = FALSE, newestOnTop = FALSE, progressBar = FALSE, position = c("top-right", "top-center", "top-left", "top-full-width", "bottom-right", "bottom-center", "bottom-left", "bottom-full-width"), preventDuplicates = FALSE, showDuration = 300, hideDuration = 1000, timeOut = 5000, extendedTimeOut = 1000, showEasing = c("swing", "linear"), hideEasing = c("swing", "linear"), showMethod = c("fadeIn", "slideDown", "show"), hideMethod = c("fadeOut", "hide"))
toastr_success(message, title = "", closeButton = FALSE, newestOnTop = FALSE, progressBar = FALSE, position = c("top-right", "top-center", "top-left", "top-full-width", "bottom-right", "bottom-center", "bottom-left", "bottom-full-width"), preventDuplicates = FALSE, showDuration = 300, hideDuration = 1000, timeOut = 5000, extendedTimeOut = 1000, showEasing = c("swing", "linear"), hideEasing = c("swing", "linear"), showMethod = c("fadeIn", "slideDown", "show"), hideMethod = c("fadeOut", "hide")) toastr_info(message, title = "", closeButton = FALSE, newestOnTop = FALSE, progressBar = FALSE, position = c("top-right", "top-center", "top-left", "top-full-width", "bottom-right", "bottom-center", "bottom-left", "bottom-full-width"), preventDuplicates = FALSE, showDuration = 300, hideDuration = 1000, timeOut = 5000, extendedTimeOut = 1000, showEasing = c("swing", "linear"), hideEasing = c("swing", "linear"), showMethod = c("fadeIn", "slideDown", "show"), hideMethod = c("fadeOut", "hide")) toastr_warning(message, title = "", closeButton = FALSE, newestOnTop = FALSE, progressBar = FALSE, position = c("top-right", "top-center", "top-left", "top-full-width", "bottom-right", "bottom-center", "bottom-left", "bottom-full-width"), preventDuplicates = FALSE, showDuration = 300, hideDuration = 1000, timeOut = 5000, extendedTimeOut = 1000, showEasing = c("swing", "linear"), hideEasing = c("swing", "linear"), showMethod = c("fadeIn", "slideDown", "show"), hideMethod = c("fadeOut", "hide")) toastr_error(message, title = "", closeButton = FALSE, newestOnTop = FALSE, progressBar = FALSE, position = c("top-right", "top-center", "top-left", "top-full-width", "bottom-right", "bottom-center", "bottom-left", "bottom-full-width"), preventDuplicates = FALSE, showDuration = 300, hideDuration = 1000, timeOut = 5000, extendedTimeOut = 1000, showEasing = c("swing", "linear"), hideEasing = c("swing", "linear"), showMethod = c("fadeIn", "slideDown", "show"), hideMethod = c("fadeOut", "hide"))
message |
Message to show. |
title |
Optional title, shown on the top. |
closeButton |
Whether to show a close button. Even if there is a close button, the notification can still be closed by clicking on it. For sticky notifications, it is good practice to show the close button, to tell the user that the notification can be closed. |
newestOnTop |
Whether to have the newest notification on the top. |
progressBar |
Whether to show a progress bar. |
position |
Where to put the notification. Possible values:
|
preventDuplicates |
Whether to prevent showing exactly the same message as the previous one. Note that only the message matters here, the title is ignored. |
showDuration |
How long the initial show transition should take, in milliseconds. |
hideDuration |
How long the final hide transition should take, in milliseconds. |
timeOut |
How long the notification should be kept on the screen,
in milliseconds. Set it to zero to keep it on the screen until it is
clicked. Note that if the mouse cursor is over the notification, then
it is kept on the screen for |
extendedTimeOut |
How long to keep the notification on the screen after the mouse cursor leaves it, in milliseconds. |
showEasing |
Animation easing to show the notification.
Possible values: |
hideEasing |
Animation easing to hide the notification.
Possible values: |
showMethod |
Animation to show the notification.
Possible values: |
hideMethod |
Animation to hide the notification.
Possible values: |
By default, the notifications disappear automatically after a timeout, unless the mouse cursor is over them.
You typically use these functions in the definition of the Shiny
server program, as a response to an event, i.e. in the output functions,
reactives, or in observe
or observeEvent
. Here is
an example that shows a note when the data was successfully written to
a database, and an error otherwise.
observeEvent( input$save_button, { tryCatch( { writeToDB(data) toastr_success("Saved to database") }, error = function(e) { toastr_error(title = "Database error", conditionMessage(e)) } }
)
## See above
## See above
Call this function once, from the top of your Shiny UI definition. Here is an example:
ui <- shinyUI(fluidPage( useToastr(), pageWithSidebar( headerPanel("Header"), sidebarPanel( ... ), mainPanel( ... ) ) ))
useToastr()
useToastr()
The HTML tags to put into the <head>
of the HTML file.
toastr_success
, toastr_info
,
toastr_warning
, toastr_error
## See above
## See above