Files
shiny/reference/Progress.html
2025-07-08 04:55:58 +00:00

302 lines
21 KiB
HTML

<!DOCTYPE html>
<!-- Generated by pkgdown: do not edit by hand --><html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Reporting progress (object-oriented API) — Progress • shiny</title><!-- jquery --><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js" integrity="sha512-v2CJ7UaYy4JwqLDIrZUI/4hqeoQieOmAZNXBeQyjo21dadnwR+8ZaIJVT8EE2iyI61OV8e6M8PP2/4hpQINQ/g==" crossorigin="anonymous" referrerpolicy="no-referrer"></script><!-- Bootstrap --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha256-bZLfwXAP04zRMK2BjiO8iu9pf4FbLqX6zitd+tIvLhE=" crossorigin="anonymous"><script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.4.1/js/bootstrap.min.js" integrity="sha256-nuL8/2cJ5NDSSwnKD8VqreErSWHtnEP9E7AySL+1ev4=" crossorigin="anonymous"></script><!-- bootstrap-toc --><link rel="stylesheet" href="../bootstrap-toc.css"><script src="../bootstrap-toc.js"></script><!-- Font Awesome icons --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/all.min.css" integrity="sha256-mmgLkCYLUQbXn0B1SRqzHar6dCnv9oZFPEC1g1cwlkk=" crossorigin="anonymous"><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/v4-shims.min.css" integrity="sha256-wZjR52fzng1pJHwx4aV2AO3yyTOXrcDW7jBpJtTwVxw=" crossorigin="anonymous"><!-- clipboard.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.6/clipboard.min.js" integrity="sha256-inc5kl9MA1hkeYUt+EC3BhlIgyp/2jDIyBLS6k3UxPI=" crossorigin="anonymous"></script><!-- headroom.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/headroom.min.js" integrity="sha256-AsUX4SJE1+yuDu5+mAVzJbuYNPHj/WroHuZ8Ir/CkE0=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/jQuery.headroom.min.js" integrity="sha256-ZX/yNShbjqsohH1k95liqY9Gd8uOiE1S4vZc+9KQ1K4=" crossorigin="anonymous"></script><!-- pkgdown --><link href="../pkgdown.css" rel="stylesheet"><script src="../pkgdown.js"></script><meta property="og:title" content="Reporting progress (object-oriented API) — Progress"><meta property="og:description" content="Reporting progress (object-oriented API)
Reporting progress (object-oriented API)"><meta property="og:image" content="/logo.png"><!-- mathjax --><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js" integrity="sha256-nvJJv9wWKEm88qvoQl9ekL2J+k/RWIsaSScxxlsrv8k=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/config/TeX-AMS-MML_HTMLorMML.js" integrity="sha256-84DKXVJXs0/F8OTMzX4UR909+jtl4G7SPypPavF+GfA=" crossorigin="anonymous"></script><!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]--></head><body data-spy="scroll" data-target="#toc">
<div class="container template-reference-topic">
<header><div class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<span class="navbar-brand">
<a class="navbar-link" href="../index.html">shiny</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="">1.11.1</span>
</span>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav"><li>
<a href="../reference/index.html">Reference</a>
</li>
<li>
<a href="../news/index.html">Changelog</a>
</li>
</ul><ul class="nav navbar-nav navbar-right"><li>
<a href="https://github.com/rstudio/shiny/" class="external-link">
<span class="fab fa-github fa-lg"></span>
</a>
</li>
</ul></div><!--/.nav-collapse -->
</div><!--/.container -->
</div><!--/.navbar -->
</header><div class="row">
<div class="col-md-9 contents">
<div class="page-header">
<h1>Reporting progress (object-oriented API)</h1>
<small class="dont-index">Source: <a href="https://github.com/rstudio/shiny/blob/main/R/progress.R" class="external-link"><code>R/progress.R</code></a></small>
<div class="hidden name"><code>Progress.Rd</code></div>
</div>
<div class="ref-description">
<p>Reporting progress (object-oriented API)</p>
<p>Reporting progress (object-oriented API)</p>
</div>
<div id="details">
<h2>Details</h2>
<p>Reports progress to the user during long-running operations.</p>
<p>This package exposes two distinct programming APIs for working with
progress. <code><a href="withProgress.html">withProgress()</a></code> and <code><a href="withProgress.html">setProgress()</a></code>
together provide a simple function-based interface, while the
<code>Progress</code> reference class provides an object-oriented API.</p>
<p>Instantiating a <code>Progress</code> object causes a progress panel to be
created, and it will be displayed the first time the <code>set</code>
method is called. Calling <code>close</code> will cause the progress panel
to be removed.</p>
<p>As of version 0.14, the progress indicators use Shiny's new notification API.
If you want to use the old styling (for example, you may have used customized
CSS), you can use <code>style="old"</code> each time you call
<code>Progress$new()</code>. If you don't want to set the style each time
<code>Progress$new</code> is called, you can instead call
<code><a href="shinyOptions.html">shinyOptions(progress.style="old")</a></code> just once, inside the server
function.</p>
</div>
<div id="see-also">
<h2>See also</h2>
<div class="dont-index"><p><code><a href="withProgress.html">withProgress()</a></code></p></div>
</div>
<div id="methods">
<h2>Methods</h2>
<div class="section">
<h3 id="public-methods">Public methods<a class="anchor" aria-label="anchor" href="#public-methods"></a></h3>
<ul><li><p><a href="#method-Progress-new"><code>Progress$new()</code></a></p></li>
<li><p><a href="#method-Progress-set"><code>Progress$set()</code></a></p></li>
<li><p><a href="#method-Progress-inc"><code>Progress$inc()</code></a></p></li>
<li><p><a href="#method-Progress-getMin"><code>Progress$getMin()</code></a></p></li>
<li><p><a href="#method-Progress-getMax"><code>Progress$getMax()</code></a></p></li>
<li><p><a href="#method-Progress-getValue"><code>Progress$getValue()</code></a></p></li>
<li><p><a href="#method-Progress-close"><code>Progress$close()</code></a></p></li>
<li><p><a href="#method-Progress-clone"><code>Progress$clone()</code></a></p></li>
</ul></div><p></p><hr><a id="method-Progress-new"></a><div class="section">
<h3 id="method-new-">Method <code><a href="https://rdrr.io/r/methods/new.html" class="external-link">new()</a></code><a class="anchor" aria-label="anchor" href="#method-new-"></a></h3>
<p>Creates a new progress panel (but does not display it).</p><div class="section">
<h4 id="usage">Usage<a class="anchor" aria-label="anchor" href="#usage"></a></h4>
<p></p><div class="r"><div class="sourceCode"><pre><code><span><span class="va"><a href="../reference/Progress.html">Progress</a></span><span class="op">$</span><span class="fu">new</span><span class="op">(</span></span>
<span> session <span class="op">=</span> <span class="fu"><a href="../reference/domains.html">getDefaultReactiveDomain</a></span><span class="op">(</span><span class="op">)</span>,</span>
<span> min <span class="op">=</span> <span class="fl">0</span>,</span>
<span> max <span class="op">=</span> <span class="fl">1</span>,</span>
<span> style <span class="op">=</span> <span class="fu"><a href="../reference/shinyOptions.html">getShinyOption</a></span><span class="op">(</span><span class="st">"progress.style"</span>, default <span class="op">=</span> <span class="st">"notification"</span><span class="op">)</span></span>
<span><span class="op">)</span></span></code></pre></div><p></p></div>
</div>
<div class="section">
<h4 id="arguments">Arguments<a class="anchor" aria-label="anchor" href="#arguments"></a></h4>
<p></p><div class="arguments"><dl><dt><code>session</code></dt>
<dd><p>The Shiny session object, as provided by <code>shinyServer</code> to
the server function.</p></dd>
<dt><code>min</code></dt>
<dd><p>The value that represents the starting point of the progress
bar. Must be less than <code>max</code>.</p></dd>
<dt><code>max</code></dt>
<dd><p>The value that represents the end of the progress bar. Must be
greater than <code>min</code>.</p></dd>
<dt><code>style</code></dt>
<dd><p>Progress display style. If <code>"notification"</code> (the default),
the progress indicator will show using Shiny's notification API. If
<code>"old"</code>, use the same HTML and CSS used in Shiny 0.13.2 and below (this
is for backward-compatibility).</p></dd>
</dl><p></p></div>
</div>
</div><p></p><hr><a id="method-Progress-set"></a><div class="section">
<h3 id="method-set-">Method <code>set()</code><a class="anchor" aria-label="anchor" href="#method-set-"></a></h3>
<p>Updates the progress panel. When called the first time, the
progress panel is displayed.</p><div class="section">
<h4 id="usage-1">Usage<a class="anchor" aria-label="anchor" href="#usage-1"></a></h4>
<p></p><div class="r"><div class="sourceCode"><pre><code><span><span class="va">Progress</span><span class="op">$</span><span class="fu">set</span><span class="op">(</span>value <span class="op">=</span> <span class="cn">NULL</span>, message <span class="op">=</span> <span class="cn">NULL</span>, detail <span class="op">=</span> <span class="cn">NULL</span><span class="op">)</span></span></code></pre></div><p></p></div>
</div>
<div class="section">
<h4 id="arguments-1">Arguments<a class="anchor" aria-label="anchor" href="#arguments-1"></a></h4>
<p></p><div class="arguments"><dl><dt><code>value</code></dt>
<dd><p>Single-element numeric vector; the value at which to set the
progress bar, relative to <code>min</code> and <code>max</code>. <code>NULL</code> hides the progress
bar, if it is currently visible.</p></dd>
<dt><code>message</code></dt>
<dd><p>A single-element character vector; the message to be
displayed to the user, or <code>NULL</code> to hide the current message (if any).</p></dd>
<dt><code>detail</code></dt>
<dd><p>A single-element character vector; the detail message to be
displayed to the user, or <code>NULL</code> to hide the current detail message (if
any). The detail message will be shown with a de-emphasized appearance
relative to <code>message</code>.</p></dd>
</dl><p></p></div>
</div>
</div><p></p><hr><a id="method-Progress-inc"></a><div class="section">
<h3 id="method-inc-">Method <code>inc()</code><a class="anchor" aria-label="anchor" href="#method-inc-"></a></h3>
<p>Like <code>set</code>, this updates the progress panel. The difference
is that <code>inc</code> increases the progress bar by <code>amount</code>, instead of
setting it to a specific value.</p><div class="section">
<h4 id="usage-2">Usage<a class="anchor" aria-label="anchor" href="#usage-2"></a></h4>
<p></p><div class="r"><div class="sourceCode"><pre><code><span><span class="va">Progress</span><span class="op">$</span><span class="fu">inc</span><span class="op">(</span>amount <span class="op">=</span> <span class="fl">0.1</span>, message <span class="op">=</span> <span class="cn">NULL</span>, detail <span class="op">=</span> <span class="cn">NULL</span><span class="op">)</span></span></code></pre></div><p></p></div>
</div>
<div class="section">
<h4 id="arguments-2">Arguments<a class="anchor" aria-label="anchor" href="#arguments-2"></a></h4>
<p></p><div class="arguments"><dl><dt><code>amount</code></dt>
<dd><p>For the <code>inc()</code> method, a numeric value to increment the
progress bar.</p></dd>
<dt><code>message</code></dt>
<dd><p>A single-element character vector; the message to be
displayed to the user, or <code>NULL</code> to hide the current message (if any).</p></dd>
<dt><code>detail</code></dt>
<dd><p>A single-element character vector; the detail message to be
displayed to the user, or <code>NULL</code> to hide the current detail message (if
any). The detail message will be shown with a de-emphasized appearance
relative to <code>message</code>.</p></dd>
</dl><p></p></div>
</div>
</div><p></p><hr><a id="method-Progress-getMin"></a><div class="section">
<h3 id="method-getmin-">Method <code>getMin()</code><a class="anchor" aria-label="anchor" href="#method-getmin-"></a></h3>
<p>Returns the minimum value.</p><div class="section">
<h4 id="usage-3">Usage<a class="anchor" aria-label="anchor" href="#usage-3"></a></h4>
<p></p><div class="r"><div class="sourceCode"><pre><code><span><span class="va">Progress</span><span class="op">$</span><span class="fu">getMin</span><span class="op">(</span><span class="op">)</span></span></code></pre></div><p></p></div>
</div>
</div><p></p><hr><a id="method-Progress-getMax"></a><div class="section">
<h3 id="method-getmax-">Method <code>getMax()</code><a class="anchor" aria-label="anchor" href="#method-getmax-"></a></h3>
<p>Returns the maximum value.</p><div class="section">
<h4 id="usage-4">Usage<a class="anchor" aria-label="anchor" href="#usage-4"></a></h4>
<p></p><div class="r"><div class="sourceCode"><pre><code><span><span class="va">Progress</span><span class="op">$</span><span class="fu">getMax</span><span class="op">(</span><span class="op">)</span></span></code></pre></div><p></p></div>
</div>
</div><p></p><hr><a id="method-Progress-getValue"></a><div class="section">
<h3 id="method-getvalue-">Method <code>getValue()</code><a class="anchor" aria-label="anchor" href="#method-getvalue-"></a></h3>
<p>Returns the current value.</p><div class="section">
<h4 id="usage-5">Usage<a class="anchor" aria-label="anchor" href="#usage-5"></a></h4>
<p></p><div class="r"><div class="sourceCode"><pre><code><span><span class="va">Progress</span><span class="op">$</span><span class="fu">getValue</span><span class="op">(</span><span class="op">)</span></span></code></pre></div><p></p></div>
</div>
</div><p></p><hr><a id="method-Progress-close"></a><div class="section">
<h3 id="method-close-">Method <code><a href="https://rdrr.io/r/base/connections.html" class="external-link">close()</a></code><a class="anchor" aria-label="anchor" href="#method-close-"></a></h3>
<p>Removes the progress panel. Future calls to <code>set</code> and
<code>close</code> will be ignored.</p><div class="section">
<h4 id="usage-6">Usage<a class="anchor" aria-label="anchor" href="#usage-6"></a></h4>
<p></p><div class="r"><div class="sourceCode"><pre><code><span><span class="va">Progress</span><span class="op">$</span><span class="fu">close</span><span class="op">(</span><span class="op">)</span></span></code></pre></div><p></p></div>
</div>
</div><p></p><hr><a id="method-Progress-clone"></a><div class="section">
<h3 id="method-clone-">Method <code>clone()</code><a class="anchor" aria-label="anchor" href="#method-clone-"></a></h3>
<p>The objects of this class are cloneable with this method.</p><div class="section">
<h4 id="usage-7">Usage<a class="anchor" aria-label="anchor" href="#usage-7"></a></h4>
<p></p><div class="r"><div class="sourceCode"><pre><code><span><span class="va">Progress</span><span class="op">$</span><span class="fu">clone</span><span class="op">(</span>deep <span class="op">=</span> <span class="cn">FALSE</span><span class="op">)</span></span></code></pre></div><p></p></div>
</div>
<div class="section">
<h4 id="arguments-3">Arguments<a class="anchor" aria-label="anchor" href="#arguments-3"></a></h4>
<p></p><div class="arguments"><dl><dt><code>deep</code></dt>
<dd><p>Whether to make a deep clone.</p></dd>
</dl><p></p></div>
</div>
</div>
</div>
<div id="ref-examples">
<h2>Examples</h2>
<div class="sourceCode"><pre class="sourceCode r"><code><span class="r-in"><span><span class="co">## Only run examples in interactive R sessions</span></span></span>
<span class="r-in"><span><span class="kw">if</span> <span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/interactive.html" class="external-link">interactive</a></span><span class="op">(</span><span class="op">)</span><span class="op">)</span> <span class="op">{</span></span></span>
<span class="r-in"><span></span></span>
<span class="r-in"><span><span class="va">ui</span> <span class="op">&lt;-</span> <span class="fu"><a href="fluidPage.html">fluidPage</a></span><span class="op">(</span></span></span>
<span class="r-in"><span> <span class="fu"><a href="plotOutput.html">plotOutput</a></span><span class="op">(</span><span class="st">"plot"</span><span class="op">)</span></span></span>
<span class="r-in"><span><span class="op">)</span></span></span>
<span class="r-in"><span></span></span>
<span class="r-in"><span><span class="va">server</span> <span class="op">&lt;-</span> <span class="kw">function</span><span class="op">(</span><span class="va">input</span>, <span class="va">output</span>, <span class="va">session</span><span class="op">)</span> <span class="op">{</span></span></span>
<span class="r-in"><span> <span class="va">output</span><span class="op">$</span><span class="va">plot</span> <span class="op">&lt;-</span> <span class="fu"><a href="renderPlot.html">renderPlot</a></span><span class="op">(</span><span class="op">{</span></span></span>
<span class="r-in"><span> <span class="va">progress</span> <span class="op">&lt;-</span> <span class="va">Progress</span><span class="op">$</span><span class="fu">new</span><span class="op">(</span><span class="va">session</span>, min<span class="op">=</span><span class="fl">1</span>, max<span class="op">=</span><span class="fl">15</span><span class="op">)</span></span></span>
<span class="r-in"><span> <span class="fu"><a href="https://rdrr.io/r/base/on.exit.html" class="external-link">on.exit</a></span><span class="op">(</span><span class="va">progress</span><span class="op">$</span><span class="fu">close</span><span class="op">(</span><span class="op">)</span><span class="op">)</span></span></span>
<span class="r-in"><span></span></span>
<span class="r-in"><span> <span class="va">progress</span><span class="op">$</span><span class="fu">set</span><span class="op">(</span>message <span class="op">=</span> <span class="st">'Calculation in progress'</span>,</span></span>
<span class="r-in"><span> detail <span class="op">=</span> <span class="st">'This may take a while...'</span><span class="op">)</span></span></span>
<span class="r-in"><span></span></span>
<span class="r-in"><span> <span class="kw">for</span> <span class="op">(</span><span class="va">i</span> <span class="kw">in</span> <span class="fl">1</span><span class="op">:</span><span class="fl">15</span><span class="op">)</span> <span class="op">{</span></span></span>
<span class="r-in"><span> <span class="va">progress</span><span class="op">$</span><span class="fu">set</span><span class="op">(</span>value <span class="op">=</span> <span class="va">i</span><span class="op">)</span></span></span>
<span class="r-in"><span> <span class="fu"><a href="https://rdrr.io/r/base/Sys.sleep.html" class="external-link">Sys.sleep</a></span><span class="op">(</span><span class="fl">0.5</span><span class="op">)</span></span></span>
<span class="r-in"><span> <span class="op">}</span></span></span>
<span class="r-in"><span> <span class="fu"><a href="https://rdrr.io/r/graphics/plot.default.html" class="external-link">plot</a></span><span class="op">(</span><span class="va">cars</span><span class="op">)</span></span></span>
<span class="r-in"><span> <span class="op">}</span><span class="op">)</span></span></span>
<span class="r-in"><span><span class="op">}</span></span></span>
<span class="r-in"><span></span></span>
<span class="r-in"><span><span class="fu"><a href="shinyApp.html">shinyApp</a></span><span class="op">(</span><span class="va">ui</span>, <span class="va">server</span><span class="op">)</span></span></span>
<span class="r-in"><span><span class="op">}</span></span></span>
</code></pre></div>
</div>
</div>
<div class="col-md-3 hidden-xs hidden-sm" id="pkgdown-sidebar">
<nav id="toc" data-toggle="toc" class="sticky-top"><h2 data-toc-skip>Contents</h2>
</nav></div>
</div>
<footer><div class="copyright">
<p></p><p>Developed by Winston Chang, Joe Cheng, JJ Allaire, Carson Sievert, Barret Schloerke, Yihui Xie, Jeff Allen, Jonathan McPherson, Alan Dipert, Barbara Borges, Posit Software, PBC.</p>
</div>
<div class="pkgdown">
<p></p><p>Site built with <a href="https://pkgdown.r-lib.org/" class="external-link">pkgdown</a> 2.1.3.</p>
</div>
</footer></div>
</body></html>