From dbbf67b0b285b7b6b60c27c50e1ca8e0a9312280 Mon Sep 17 00:00:00 2001 From: pvictor Date: Mon, 30 Sep 2024 09:29:22 +0200 Subject: [PATCH] added example for loading() --- R/loading.R | 5 ++-- _pkgdown.yml | 5 +--- examples/loading.R | 70 +++++++++++++++++++++++++++++++++++++++++++ man/loading.Rd | 74 +++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 147 insertions(+), 7 deletions(-) create mode 100644 examples/loading.R diff --git a/R/loading.R b/R/loading.R index 2077671..f78513c 100644 --- a/R/loading.R +++ b/R/loading.R @@ -10,8 +10,9 @@ #' #' @return a `list` that can be used in [capture()] or [capture_pdf()]. #' @export -#' -loading <- function(text = "Generating PDF, please wait...", +#' +#' @example examples/loading.R +loading <- function(text = "Capturing screenshot, please wait...", type = c("standard", "hourglass", "circle", "arrows", "dots", "pulse"), color = "#246abe", background = "rgba(0,0,0,0.8)", diff --git a/_pkgdown.yml b/_pkgdown.yml index fa57642..e363e46 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -2,14 +2,11 @@ url: https://dreamrs.github.io/capture template: bootstrap: 5 - bootswatch: zephyr + bootswatch: sandstone bslib: base_font: {google: "Poppins"} primary: "#112446" -navbar: - bg: primary - authors: Victor Perrier: href: https://twitter.com/_pvictorr diff --git a/examples/loading.R b/examples/loading.R new file mode 100644 index 0000000..0eeca84 --- /dev/null +++ b/examples/loading.R @@ -0,0 +1,70 @@ +library(shiny) +library(capture) + +ui <- fluidPage( + tags$h2("Capture (loading) example"), + capture( + selector = "body", + filename = "all-page", + scale = 5, + icon("camera"), "Auto loading indicator", + loading = loading( + text = "Capturing screenshot...", + type = "arrows", + color = "firebrick", + size = "160px" + ) + ), + tags$br(), + fluidRow( + column( + width = 4, + wellPanel( + tags$b("Parameters :"), + selectInput( + inputId = "loi", + label = "Law:", + choices = c("normal", "uniform", "exponential") + ) + ) + ), + column( + width = 8, + tags$div( + id = "result-block", + tags$b("Results :"), + plotOutput(outputId = "plot"), + uiOutput(outputId = "mean"), + verbatimTextOutput(outputId = "raw") + ) + ) + ) +) + +server <- function(input, output, session) { + + distrib_r <- reactive({ + switch( + input$loi, + "normal" = rnorm(1000), + "uniform" = runif(1000), + "exponential" = rexp(1000) + ) + }) + + output$plot <- renderPlot({ + hist(distrib_r()) + }) + + output$mean <- renderUI({ + tags$p(tags$b("The mean is :"), round(mean(distrib_r()), 2)) + }) + + output$raw <- renderPrint({ + summary(distrib_r()) + }) + +} + +if (interactive()) + shinyApp(ui, server) diff --git a/man/loading.Rd b/man/loading.Rd index 59ed157..e7c3386 100644 --- a/man/loading.Rd +++ b/man/loading.Rd @@ -5,7 +5,7 @@ \title{Loading indicator to be displayed when generating screenshot} \usage{ loading( - text = "Generating PDF, please wait...", + text = "Capturing screenshot, please wait...", type = c("standard", "hourglass", "circle", "arrows", "dots", "pulse"), color = "#246abe", background = "rgba(0,0,0,0.8)", @@ -32,3 +32,75 @@ a \code{list} that can be used in \code{\link[=capture]{capture()}} or \code{\li \description{ Loading indicator to be displayed when generating screenshot } +\examples{ +library(shiny) +library(capture) + +ui <- fluidPage( + tags$h2("Capture (loading) example"), + capture( + selector = "body", + filename = "all-page", + scale = 5, + icon("camera"), "Auto loading indicator", + loading = loading( + text = "Capturing screenshot...", + type = "arrows", + color = "firebrick", + size = "160px" + ) + ), + tags$br(), + fluidRow( + column( + width = 4, + wellPanel( + tags$b("Parameters :"), + selectInput( + inputId = "loi", + label = "Law:", + choices = c("normal", "uniform", "exponential") + ) + ) + ), + column( + width = 8, + tags$div( + id = "result-block", + tags$b("Results :"), + plotOutput(outputId = "plot"), + uiOutput(outputId = "mean"), + verbatimTextOutput(outputId = "raw") + ) + ) + ) +) + +server <- function(input, output, session) { + + distrib_r <- reactive({ + switch( + input$loi, + "normal" = rnorm(1000), + "uniform" = runif(1000), + "exponential" = rexp(1000) + ) + }) + + output$plot <- renderPlot({ + hist(distrib_r()) + }) + + output$mean <- renderUI({ + tags$p(tags$b("The mean is :"), round(mean(distrib_r()), 2)) + }) + + output$raw <- renderPrint({ + summary(distrib_r()) + }) + +} + +if (interactive()) + shinyApp(ui, server) +}