Title: | Pretty Notifications for 'Shiny' |
---|---|
Description: | This is a wrapper of the 'React' library 'React-Toastify'. It allows to show some notifications (toasts) in 'Shiny' applications. There are options for the style, the position, the transition effect, and more. |
Authors: | Stéphane Laurent [aut, cre], Fadi Khadra [cph] ('React-Toastify' library (https://fkhadra.github.io/react-toastify/introduction)) |
Maintainer: | Stéphane Laurent <[email protected]> |
License: | GPL-3 |
Version: | 2.0.0 |
Built: | 2024-11-21 04:35:00 UTC |
Source: | https://github.com/stla/shinytoastify |
A function to run examples of Shiny apps using the
shinyToastify
package.
shinyToastifyExample(example, display.mode = "showcase", ...)
shinyToastifyExample(example, display.mode = "showcase", ...)
example |
example name |
display.mode |
the display mode to use when running the example; see
|
... |
arguments passed to |
No return value, just launches a Shiny app.
if(interactive()){ shinyToastifyExample("bodyClassName") } if(interactive()){ shinyToastifyExample("className") } if(interactive()){ shinyToastifyExample("progressClassName") } if(interactive()){ shinyToastifyExample("TypeAndTransition") }
if(interactive()){ shinyToastifyExample("bodyClassName") } if(interactive()){ shinyToastifyExample("className") } if(interactive()){ shinyToastifyExample("progressClassName") } if(interactive()){ shinyToastifyExample("TypeAndTransition") }
List of examples.
shinyToastifyExamples()
shinyToastifyExamples()
No return value, just prints a message listing the example names.
shinyToastifyExamples() if(interactive()){ shinyToastifyExample("TypeAndTransition") }
shinyToastifyExamples() if(interactive()){ shinyToastifyExample("TypeAndTransition") }
Show a toast in a Shiny application.
showToast( session, input, id = NULL, text, type = "default", position = "top-right", transition = "slide", autoClose = 5000, hideProgressBar = FALSE, newestOnTop = FALSE, closeOnClick = TRUE, rtl = FALSE, pauseOnFocusLoss = TRUE, draggable = TRUE, draggableDirection = "x", draggablePercent = 80, pauseOnHover = TRUE, className = NULL, toastClassName = NULL, bodyClassName = NULL, progressClassName = NULL, style = NULL, Rcallback = function() { NULL }, JScallback = NULL )
showToast( session, input, id = NULL, text, type = "default", position = "top-right", transition = "slide", autoClose = 5000, hideProgressBar = FALSE, newestOnTop = FALSE, closeOnClick = TRUE, rtl = FALSE, pauseOnFocusLoss = TRUE, draggable = TRUE, draggableDirection = "x", draggablePercent = 80, pauseOnHover = TRUE, className = NULL, toastClassName = NULL, bodyClassName = NULL, progressClassName = NULL, style = NULL, Rcallback = function() { NULL }, JScallback = NULL )
session |
the Shiny |
input |
the Shiny |
id |
an id for the toast or |
text |
the text displayed in the toast; this can be a character string,
an html element created with the |
type |
toast type, one of |
position |
toast position, one of |
transition |
the transition effect, one of |
autoClose |
either a number, the time in ms to close the toast, or
|
hideProgressBar |
Boolean, whether to hide the progress bar |
newestOnTop |
Boolean, whether to display newest toast on top |
closeOnClick |
Boolean, whether to dismiss the toast on click |
rtl |
Boolean, right to left |
pauseOnFocusLoss |
Boolean, whether to pause the toast on focus loss |
draggable |
Boolean, ability to drag the toast to remove it |
draggableDirection |
|
draggablePercent |
the percentage of the width of the toast needed to remove it by dragging |
pauseOnHover |
Boolean, whether to pause the toast on hover |
className |
name of a CSS class applied to the container |
toastClassName |
name of a CSS class applied on the toast wrapper |
bodyClassName |
name of a CSS class applied on the toast body |
progressClassName |
name of a CSS class applied on the progress bar |
style |
inline style applied to the container, e.g.
|
Rcallback |
a R function without arguments to be executed whenever the
toast is closed; alternatively, use the |
JScallback |
some JavaScript code given as a string to be executed
whenever the toast is closed, e.g. |
Usage of the id
argument. If you provide a string
to the id
argument, say "mytoast"
, the application will
send the event input[["mytoast_closed"]]
to the server whenever
the toast closes; therefore you can listen to this event with an observer
to perform an action whenever the toast closes.
No return value, called for side effect.
library(shiny) library(shinyToastify) ui <- fluidPage( useShinyToastify(), br(), actionButton("btn", "Show toast", class = "btn-primary btn-lg") ) server <- function(input, output, session){ toastTransitions <- c( "Zoom", "Bounce", "Flip", "Slide" ) observeEvent(input[["btn"]], { toastTransition <- toastTransitions[1L + (input[["btn"]] %% 4L)] html <- HTML( '<span style="font-size: 30px; font-family: cursive;">', paste0(toastTransition, " transition"), '</span>', ) showToast( session, input, text = html, type = "success", transition = tolower(toastTransition), autoClose = 3000, style = list( border = "4px solid crimson", boxShadow = "rgba(0, 0, 0, 0.56) 0px 22px 30px 4px" ) ) }) } if(interactive()){ shinyApp(ui, server) }
library(shiny) library(shinyToastify) ui <- fluidPage( useShinyToastify(), br(), actionButton("btn", "Show toast", class = "btn-primary btn-lg") ) server <- function(input, output, session){ toastTransitions <- c( "Zoom", "Bounce", "Flip", "Slide" ) observeEvent(input[["btn"]], { toastTransition <- toastTransitions[1L + (input[["btn"]] %% 4L)] html <- HTML( '<span style="font-size: 30px; font-family: cursive;">', paste0(toastTransition, " transition"), '</span>', ) showToast( session, input, text = html, type = "success", transition = tolower(toastTransition), autoClose = 3000, style = list( border = "4px solid crimson", boxShadow = "rgba(0, 0, 0, 0.56) 0px 22px 30px 4px" ) ) }) } if(interactive()){ shinyApp(ui, server) }
Update a toast in a Shiny application. Run
shinyToastifyExample("toastUpdate")
for an example.
toastUpdate( session, toastId, text, type = "default", position = "top-right", transition = "slide", autoClose = 5000, hideProgressBar = FALSE, closeOnClick = TRUE, rtl = FALSE, pauseOnFocusLoss = TRUE, draggable = TRUE, draggableDirection = "x", draggablePercent = 80, pauseOnHover = TRUE, className = NULL, toastClassName = NULL, bodyClassName = NULL, progressClassName = NULL, style = NULL, JScallback = NULL )
toastUpdate( session, toastId, text, type = "default", position = "top-right", transition = "slide", autoClose = 5000, hideProgressBar = FALSE, closeOnClick = TRUE, rtl = FALSE, pauseOnFocusLoss = TRUE, draggable = TRUE, draggableDirection = "x", draggablePercent = 80, pauseOnHover = TRUE, className = NULL, toastClassName = NULL, bodyClassName = NULL, progressClassName = NULL, style = NULL, JScallback = NULL )
session |
the Shiny |
toastId |
the id of the toast to be updated ( |
text |
the text displayed in the toast; this can be a character string,
an html element created with the |
type |
toast type, one of |
position |
toast position, one of |
transition |
the transition effect, one of |
autoClose |
either a number, the time in ms to close the toast, or
|
hideProgressBar |
Boolean, whether to hide the progress bar |
closeOnClick |
Boolean, whether to dismiss the toast on click |
rtl |
Boolean, right to left |
pauseOnFocusLoss |
Boolean, whether to pause the toast on focus loss |
draggable |
Boolean, ability to drag the toast to remove it |
draggableDirection |
|
draggablePercent |
the percentage of the width of the toast needed to remove it by dragging |
pauseOnHover |
Boolean, whether to pause the toast on hover |
className |
name of a CSS class applied to the container |
toastClassName |
name of a CSS class applied on the toast wrapper |
bodyClassName |
name of a CSS class applied on the toast body |
progressClassName |
name of a CSS class applied on the progress bar |
style |
inline style applied to the container, e.g.
|
JScallback |
some JavaScript code given as a string to be executed
whenever the toast is closed; it will have an effect only if the
|
No return value, called for side effect.
This function must be called once in your Shiny ui
to
allow to use showToast
.
useShinyToastify()
useShinyToastify()
An object of class shiny.tag.list
.