JohnCoene / awn

Awesome notifications for shiny

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

awn

Awesome notifications for shiny.

Installation

Install from Github.

# install.packages("remotes")
remotes::install_github("JohnCoene/awn")

Demo

Run the gallery to view a demo app and the functionalities of the package.

awn::gallery()

Notify

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)

Modal

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)

Ask

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)

Options

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)

About

Awesome notifications for shiny

License:Other


Languages

Language:R 56.0%Language:JavaScript 44.0%