Skip to content

Commit

Permalink
added config_report()
Browse files Browse the repository at this point in the history
  • Loading branch information
pvictor committed Feb 22, 2022
1 parent ed67e57 commit 5dda11f
Show file tree
Hide file tree
Showing 8 changed files with 302 additions and 21 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export(add_busy_gif)
export(add_busy_spinner)
export(add_loading_state)
export(busy_start_up)
export(config_report)
export(hide_spinner)
export(html_dependency_epic)
export(html_dependency_freezeframe)
Expand Down
103 changes: 92 additions & 11 deletions R/report.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
#'
#' @param title Title of the report.
#' @param text Text to be displayed.
#' @param ... Options passed to JavaScript method, see [config_report()].
#' @param button Label for the button.
#' @param ... Options passed to JavaScript method, see
#' [https://notiflix.github.io/documentation](https://notiflix.github.io/documentation).
#' @param type Type of notification: `success`, `failure`, `info` or `warning`.
#' @param session Default Shiny session.
#'
Expand All @@ -27,8 +26,8 @@
#' @example examples/report.R
report <- function(title,
text,
button = "Ok",
...,
button = "Ok",
type = c("success", "failure", "info", "warning"),
session = shiny::getDefaultReactiveDomain()) {
stopifnot("'title' must be a character string" = is.character(title))
Expand All @@ -38,6 +37,8 @@ report <- function(title,
stopifnot("'button' must be a character string" = is.character(button))
type <- match.arg(type)
config <- list(...)
idx <- vapply(X = config, FUN = inherits, what = "config_report", FUN.VALUE = logical(1))
config <- c(config[!idx], unlist(config[idx], recursive = FALSE))
if (inherits(text, c("shiny.tag", "shiny.tag.list"))) {
config$plainText <- FALSE
text <- doRenderTags(text)
Expand Down Expand Up @@ -66,8 +67,8 @@ report <- function(title,
#' @rdname report
report_success <- function(title,
text,
button = "Ok",
...) {
...,
button = "Ok") {
report(
title = title,
text = text,
Expand All @@ -83,8 +84,8 @@ report_success <- function(title,
#' @rdname report
report_failure <- function(title,
text,
button = "Ok",
...) {
...,
button = "Ok") {
report(
title = title,
text = text,
Expand All @@ -99,8 +100,8 @@ report_failure <- function(title,
#' @rdname report
report_info <- function(title,
text,
button = "Ok",
...) {
...,
button = "Ok") {
report(
title = title,
text = text,
Expand All @@ -115,8 +116,8 @@ report_info <- function(title,
#' @rdname report
report_warning <- function(title,
text,
button = "Ok",
...) {
...,
button = "Ok") {
report(
title = title,
text = text,
Expand All @@ -126,3 +127,83 @@ report_warning <- function(title,
)
}





#' @title Configure options for [report()] and others
#'
#' @description Options for [report()] functions, see
#' [online documentation](https://notiflix.github.io/documentation)
#' for default values and examples.
#'
#' @param svgColor Changes the built-in SVG icon color.
#' @param titleColor Changes the title text color.
#' @param messageColor Changes the message text color.
#' @param buttonBackground Changes the button background color.
#' @param buttonColor Changes the button text color.
#' @param backOverlayColor Changes the color of the background overlay.
#' @param className Changes the class name (attribute).
#' @param width Changes the width.
#' @param backgroundColor Changes the background color.
#' @param borderRadius Changes the radius of the corners.
#' @param rtl Specifies the text direction to "right-to-left".
#' @param zindex Changes the z-index.
#' @param backOverlay Adds a background overlay.
#' @param fontFamily Changes the font-family.
#' @param svgSize Changes the built-in SVG icons width and height. (Notiflix uses square scaled icons.)
#' @param plainText Strips all HTML tags.
#' @param titleFontSize Changes the font-size of the title text.
#' @param titleMaxLength The maximum length of the title text.
#' @param messageFontSize Changes the font-size of the message text.
#' @param messageMaxLength The maximum length of the message text.
#' @param buttonFontSize Changes the font-size of the button text.
#' @param buttonMaxLength The maximum length of the button text.
#' @param cssAnimation Enables/disables CSS animations to show/hide.
#' @param cssAnimationDuration Changes the CSS animations duration as milliseconds.
#' @param cssAnimationStyle 2 types of styles can be used: fade zoom.
#' @param ... Other potential arguments.
#'
#' @return A config `list` that can be used in [report()] and other `report_*` functions.
#' @export
#'
#' @example examples/config_report.R
config_report <- function(svgColor = NULL,
titleColor = NULL,
messageColor = NULL,
buttonBackground = NULL,
buttonColor = NULL,
backOverlayColor = NULL,
className = NULL,
width = NULL,
backgroundColor = NULL,
borderRadius = NULL,
rtl = NULL,
zindex = NULL,
backOverlay = NULL,
fontFamily = NULL,
svgSize = NULL,
plainText = NULL,
titleFontSize = NULL,
titleMaxLength = NULL,
messageFontSize = NULL,
messageMaxLength = NULL,
buttonFontSize = NULL,
buttonMaxLength = NULL,
cssAnimation = NULL,
cssAnimationDuration = NULL,
cssAnimationStyle = NULL,
...) {
config <- c(as.list(environment()), list(...))
config$success <- config$failure <- dropNulls(config[1:6])
config$info <- config$warning <- dropNulls(config[1:6])
config[1:6] <- NULL
config <- dropNulls(config)
class(config) <- c(class(config), "config_report")
return(config)
}





49 changes: 49 additions & 0 deletions examples/config_report.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
library(shiny)
library(shinybusy)

ui <- fluidPage(
tags$h2("Config for report() examples"),
actionButton("success", "Success"),
actionButton("failure", "Failure"),
actionButton("info", "Info")
)

server <- function(input, output, session) {

observeEvent(input$success, {
report_success(
"Well done!",
"All in order",
config_report(
svgColor = "#0431B4",
titleColor = "#0431B4"
)
)
})

observeEvent(input$failure, {
report_failure(
"Oups...",
"Something went wrong",
config_report(
svgColor = "#DF01D7",
titleColor = "#DF01D7"
)
)
})

observeEvent(input$info, {
report_info(
"For your information",
tags$p(
style = "font-style: italic;",
"Lorem ipsum dolor sit amet"
),
config_report(width = "560px", borderRadius = "5px")
)
})

}

if (interactive())
shinyApp(ui, server)
1 change: 1 addition & 0 deletions examples/notify.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
library(shiny)
library(shinybusy)

ui <- fluidPage(
tags$h2("notify examples"),
Expand Down
3 changes: 2 additions & 1 deletion examples/report.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
library(shiny)
library(shinybusy)

ui <- fluidPage(
tags$h2("report examples"),
tags$h2("Report examples"),
tags$p(
"More examples available on the official website:",
tags$a("https://notiflix.github.io/report")
Expand Down
147 changes: 147 additions & 0 deletions man/config_report.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/notify.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5dda11f

Please sign in to comment.