Awesome notifications for shiny.
Install from Github.
# install.packages("remotes")
remotes::install_github("JohnCoene/awn")
Run the gallery
to view a demo app and the functionalities of
the package.
awn::gallery()
Show a notification.
Place useAwn
in the UI.
library(awn)
library(shiny)
ui <- fluidPage(
useAwn(),
actionButton("show", "Show")
)
server <- function(input, output, session) {
observeEvent(input$show, {
type <- sample(
c("tip", "info", "warning", "success", "alert"),
1
)
notify(
"Hello {awn}!",
type = type
)
})
}
shinyApp(ui, server)
Display a modal. Place useAwn
in the UI.
library(awn)
library(shiny)
ui <- fluidPage(
useAwn(),
actionButton("show", "Show")
)
server <- function(input, output, session) {
observeEvent(input$show, {
modal(
h1("Hello {awn}!")
)
})
}
shinyApp(ui, server)
Prompt the user.
Place useAwn
in the UI.
library(awn)
library(shiny)
ui <- fluidPage(
useAwn(),
actionButton("show", "Show")
)
server <- function(input, output, session) {
observeEvent(input$show, {
ask(
"confirmed", # id of input
p("Are you sure?")
)
})
observeEvent(input$confirmed, {
print(input$confirmed)
})
}
shinyApp(ui, server)
There are numerous options that are not hard-coded but nonetheless accessible.
You can also define global options to avoid having to repeat options at every notification, modal, etc.
library(awn)
library(shiny)
ui <- fluidPage(
useAwn(),
actionButton("show", "Show")
)
server <- function(input, output, session) {
awn_globals(durations = list(tip = 10000))
observeEvent(input$show, {
notify(
"Hello {awn}!",
type = "tip",
labels = list(
tip = "ADVICE"
)
)
})
}
shinyApp(ui, server)