R/progress.R

Defines functions withCrunchyProgress

Documented in withCrunchyProgress

#' Display progress from Crunch API processes
#'
#' Some potentially large operations, such as imports and exports, report
#' progress in the Crunch API. In an interactive R session, they print a text
#' progress bar. This context, which wraps [shiny::withProgress()], reports that
#' Crunch API progress up to the Shiny web app.
#'
#' @param expr Code to evaluate
#' @param ... Additional arguments passed to [shiny::withProgress()]
#' @return The result of `expr`
#' @export
#' @importFrom shiny setProgress withProgress
#' @examples
#' \dontrun{
#' withCrunchyProgress(
#'     ds <- newDataset(df),
#'     message = "Importing..."
#' )
#' }
withCrunchyProgress <- function(expr, ...) {
    tracer <- quote({
        setup_progress_bar <- function (...) NULL
        update_progress_bar <- function (p, value) {
            setProgress(value, message=NULL)
        }
        close <- function (...) NULL
    })
    trace("pollProgress", tracer=tracer, where=crGET)
    on.exit(untrace("pollProgress", where=crGET))
    withProgress(expr, min=0, max=100, value=0, ...)
}

Try the crunchy package in your browser

Any scripts or data that you put into this service are public.

crunchy documentation built on Jan. 16, 2021, 5:17 p.m.