| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/progress.R |
| 3 |
\name{withProgress} |
| 4 |
\alias{withProgress} |
| 5 |
\alias{setProgress} |
| 6 |
\alias{incProgress} |
| 7 |
\title{Reporting progress (functional API)} |
| 8 |
\usage{ |
| 9 |
withProgress( |
| 10 |
expr, |
| 11 |
min = 0, |
| 12 |
max = 1, |
| 13 |
value = min + (max - min) * 0.1, |
| 14 |
message = NULL, |
| 15 |
detail = NULL, |
| 16 |
style = getShinyOption("progress.style", default = "notification"), |
| 17 |
session = getDefaultReactiveDomain(), |
| 18 |
env = parent.frame(), |
| 19 |
quoted = FALSE |
| 20 |
) |
| 21 |
|
| 22 |
setProgress( |
| 23 |
value = NULL, |
| 24 |
message = NULL, |
| 25 |
detail = NULL, |
| 26 |
session = getDefaultReactiveDomain() |
| 27 |
) |
| 28 |
|
| 29 |
incProgress( |
| 30 |
amount = 0.1, |
| 31 |
message = NULL, |
| 32 |
detail = NULL, |
| 33 |
session = getDefaultReactiveDomain() |
| 34 |
) |
| 35 |
} |
| 36 |
\arguments{ |
| 37 |
\item{expr}{The work to be done. This expression should contain calls to |
| 38 |
\code{\link[=setProgress]{setProgress()}} or \code{\link[=incProgress]{incProgress()}}.} |
| 39 |
|
| 40 |
\item{min}{The value that represents the starting point of the progress bar. |
| 41 |
Must be less tham \code{max}. Default is 0.} |
| 42 |
|
| 43 |
\item{max}{The value that represents the end of the progress bar. Must be |
| 44 |
greater than \code{min}. Default is 1.} |
| 45 |
|
| 46 |
\item{value}{Single-element numeric vector; the value at which to set the |
| 47 |
progress bar, relative to \code{min} and \code{max}.} |
| 48 |
|
| 49 |
\item{message}{A single-element character vector; the message to be displayed |
| 50 |
to the user, or \code{NULL} to hide the current message (if any).} |
| 51 |
|
| 52 |
\item{detail}{A single-element character vector; the detail message to be |
| 53 |
displayed to the user, or \code{NULL} to hide the current detail message |
| 54 |
(if any). The detail message will be shown with a de-emphasized appearance |
| 55 |
relative to \code{message}.} |
| 56 |
|
| 57 |
\item{style}{Progress display style. If \code{"notification"} (the default), |
| 58 |
the progress indicator will show using Shiny's notification API. If |
| 59 |
\code{"old"}, use the same HTML and CSS used in Shiny 0.13.2 and below |
| 60 |
(this is for backward-compatibility).} |
| 61 |
|
| 62 |
\item{session}{The Shiny session object, as provided by \code{shinyServer} to |
| 63 |
the server function. The default is to automatically find the session by |
| 64 |
using the current reactive domain.} |
| 65 |
|
| 66 |
\item{env}{The environment in which \code{expr} should be evaluated.} |
| 67 |
|
| 68 |
\item{quoted}{Whether \code{expr} is a quoted expression (this is not |
| 69 |
common).} |
| 70 |
|
| 71 |
\item{amount}{For \code{incProgress}, the amount to increment the status bar. |
| 72 |
Default is 0.1.} |
| 73 |
} |
| 74 |
\value{ |
| 75 |
The result of \code{expr}. |
| 76 |
} |
| 77 |
\description{ |
| 78 |
Reports progress to the user during long-running operations. |
| 79 |
} |
| 80 |
\details{ |
| 81 |
This package exposes two distinct programming APIs for working with progress. |
| 82 |
Using \code{withProgress} with \code{incProgress} or \code{setProgress} |
| 83 |
provide a simple function-based interface, while the \code{\link[=Progress]{Progress()}} |
| 84 |
reference class provides an object-oriented API. |
| 85 |
|
| 86 |
Use \code{withProgress} to wrap the scope of your work; doing so will cause a |
| 87 |
new progress panel to be created, and it will be displayed the first time |
| 88 |
\code{incProgress} or \code{setProgress} are called. When \code{withProgress} |
| 89 |
exits, the corresponding progress panel will be removed. |
| 90 |
|
| 91 |
The \code{incProgress} function increments the status bar by a specified |
| 92 |
amount, whereas the \code{setProgress} function sets it to a specific value, |
| 93 |
and can also set the text displayed. |
| 94 |
|
| 95 |
Generally, \code{withProgress}/\code{incProgress}/\code{setProgress} should |
| 96 |
be sufficient; the exception is if the work to be done is asynchronous (this |
| 97 |
is not common) or otherwise cannot be encapsulated by a single scope. In that |
| 98 |
case, you can use the \code{Progress} reference class. |
| 99 |
|
| 100 |
As of version 0.14, the progress indicators use Shiny's new notification API. |
| 101 |
If you want to use the old styling (for example, you may have used customized |
| 102 |
CSS), you can use \code{style="old"} each time you call |
| 103 |
\code{withProgress()}. If you don't want to set the style each time |
| 104 |
\code{withProgress} is called, you can instead call |
| 105 |
\code{\link[=shinyOptions]{shinyOptions(progress.style="old")}} just once, inside the server |
| 106 |
function. |
| 107 |
} |
| 108 |
\examples{ |
| 109 |
## Only run examples in interactive R sessions |
| 110 |
if (interactive()) { |
| 111 |
options(device.ask.default = FALSE) |
| 112 |
|
| 113 |
ui <- fluidPage( |
| 114 |
plotOutput("plot") |
| 115 |
) |
| 116 |
|
| 117 |
server <- function(input, output) { |
| 118 |
output$plot <- renderPlot({ |
| 119 |
withProgress(message = 'Calculation in progress', |
| 120 |
detail = 'This may take a while...', value = 0, { |
| 121 |
for (i in 1:15) { |
| 122 |
incProgress(1/15) |
| 123 |
Sys.sleep(0.25) |
| 124 |
} |
| 125 |
}) |
| 126 |
plot(cars) |
| 127 |
}) |
| 128 |
} |
| 129 |
|
| 130 |
shinyApp(ui, server) |
| 131 |
} |
| 132 |
} |
| 133 |
\seealso{ |
| 134 |
\code{\link[=Progress]{Progress()}} |
| 135 |
} |