Built site for shiny: 1.7.1.9003@8a5da25

This commit is contained in:
cpsievert
2022-06-14 14:23:43 +00:00
parent 84ad219908
commit e7bdceedcb
182 changed files with 1847 additions and 317 deletions

View File

@@ -72,12 +72,17 @@ cache) and they can be shared across user sessions. This allows
<h2>Arguments</h2>
<dl><dt>x</dt>
<dd><p>The object to add caching to.</p></dd>
<dt>...</dt>
<dd><p>One or more expressions to use in the caching key.</p></dd>
<dt>cache</dt>
<dd><p>The scope of the cache, or a cache object. This can be <code>"app"</code>
(the default), <code>"session"</code>, or a cache object like a
<code><a href="https://cachem.r-lib.org/reference/cache_disk.html" class="external-link">cachem::cache_disk()</a></code>. See the Cache Scoping section for more information.</p></dd>
</dl></div>
<div id="details">
<h2>Details</h2>
@@ -192,18 +197,21 @@ persists beyond the current R session.</p>
<code><a href="shinyOptions.html">shinyOptions()</a></code> at the top of your app.R, server.R, or
global.R. For example, this will create a cache with 500 MB of space
instead of the default 200 MB:</p>
<p></p><div class="sourceCode"><pre><code></code></pre><p></p></div>
<p></p><div class="sourceCode"><pre><code><span id="cb1-1"><a href="#cb1-1"></a><span class="kw">shinyOptions</span>(<span class="dt">cache =</span> cachem<span class="op">::</span><span class="kw">cache_mem</span>(<span class="dt">max_size =</span> <span class="fl">500e6</span>))</span></code></pre><p></p></div>
<p>To use different settings for a session-scoped cache, you can set
<code>self$cache</code> at the top of your server function. By default, it will create
a 200 MB memory cache for each session, but you can replace it with
something different. To use the session-scoped cache, you must also call
<code>bindCache()</code> with <code>cache="session"</code>. This will create a 100 MB cache for
the session:</p>
<p></p><div class="sourceCode"><pre><code></code></pre><p></p></div>
<p></p><div class="sourceCode"><pre><code><span id="cb1-1"><a href="#cb1-1"></a><span class="cf">function</span>(input, output, session) {</span>
<span id="cb1-2"><a href="#cb1-2"></a> session<span class="op">$</span>cache &lt;-<span class="st"> </span>cachem<span class="op">::</span><span class="kw">cache_mem</span>(<span class="dt">max_size =</span> <span class="fl">100e6</span>)</span>
<span id="cb1-3"><a href="#cb1-3"></a> ...</span>
<span id="cb1-4"><a href="#cb1-4"></a>}</span></code></pre><p></p></div>
<p>If you want to use a cache that is shared across multiple R processes, you
can use a <code><a href="https://cachem.r-lib.org/reference/cache_disk.html" class="external-link">cachem::cache_disk()</a></code>. You can create a application-level shared
cache by putting this at the top of your app.R, server.R, or global.R:</p>
<p></p><div class="sourceCode"><pre><code></code></pre><p></p></div>
<p></p><div class="sourceCode"><pre><code><span id="cb1-1"><a href="#cb1-1"></a><span class="kw">shinyOptions</span>(<span class="dt">cache =</span> cachem<span class="op">::</span><span class="kw">cache_disk</span>(<span class="kw">file.path</span>(<span class="kw">dirname</span>(<span class="kw">tempdir</span>()), <span class="st">"myapp-cache"</span>))</span></code></pre><p></p></div>
<p>This will create a subdirectory in your system temp directory named
<code>myapp-cache</code> (replace <code>myapp-cache</code> with a unique name of
your choosing). On most platforms, this directory will be removed when
@@ -212,7 +220,7 @@ stops of the R process, as long as you do not reboot.</p>
<p>To have the cache persist even across multiple reboots, you can create the
cache in a location outside of the temp directory. For example, it could
be a subdirectory of the application:</p>
<p></p><div class="sourceCode"><pre><code></code></pre><p></p></div>
<p></p><div class="sourceCode"><pre><code><span id="cb1-1"><a href="#cb1-1"></a><span class="kw">shinyOptions</span>(<span class="dt">cache =</span> cachem<span class="op">::</span><span class="kw">cache_disk</span>(<span class="st">"./myapp-cache"</span>))</span></code></pre><p></p></div>
<p>In this case, resetting the cache will have to be done manually, by deleting
the directory.</p>
<p>You can also scope a cache to just one item, or selected items. To do that,
@@ -273,7 +281,8 @@ the cache.</p>
<code><a href="https://rdrr.io/pkg/htmlwidgets/man/htmlwidgets-shiny.html" class="external-link">htmlwidgets::shinyRenderWidget()</a></code>, if you've authored an htmlwidget) in
order for <code>bindCache()</code> to correctly compute a cache key.</p>
<p>The potential problem is a cache collision. Consider the following:</p>
<p></p><div class="sourceCode"><pre><code></code></pre><p></p></div>
<p></p><div class="sourceCode"><pre><code><span id="cb1-1"><a href="#cb1-1"></a>output<span class="op">$</span>x1 &lt;-<span class="st"> </span><span class="kw">renderText</span>({ input<span class="op">$</span>x }) <span class="op">%&gt;%</span><span class="st"> </span><span class="kw">bindCache</span>(input<span class="op">$</span>x)</span>
<span id="cb1-2"><a href="#cb1-2"></a>output<span class="op">$</span>x2 &lt;-<span class="st"> </span><span class="kw">renderText</span>({ input<span class="op">$</span>x <span class="op">*</span><span class="st"> </span><span class="dv">2</span> }) <span class="op">%&gt;%</span><span class="st"> </span><span class="kw">bindCache</span>(input<span class="op">$</span>x)</span></code></pre><p></p></div>
<p>Both <code>output$x1</code> and <code>output$x2</code> use <code>input$x</code> as part of their cache key,
but if it were the only thing used in the cache key, then the two outputs
would have a cache collision, and they would have the same output. To avoid
@@ -307,7 +316,16 @@ that may influence the final value.</p>
again, you can inspect the cache hint with <code>shiny:::extractCacheHint()</code> and
also test it in an application. If you do need to explicitly provide a
cache hint, pass it to <code>shinyRenderWidget</code>. For example:</p>
<p></p><div class="sourceCode"><pre><code></code></pre><p></p></div>
<p></p><div class="sourceCode"><pre><code><span id="cb1-1"><a href="#cb1-1"></a>renderMyWidget &lt;-<span class="st"> </span><span class="cf">function</span>(expr) {</span>
<span id="cb1-2"><a href="#cb1-2"></a> q &lt;-<span class="st"> </span>rlang<span class="op">::</span><span class="kw">enquo0</span>(expr)</span>
<span id="cb1-3"><a href="#cb1-3"></a></span>
<span id="cb1-4"><a href="#cb1-4"></a> htmlwidgets<span class="op">::</span><span class="kw">shinyRenderWidget</span>(</span>
<span id="cb1-5"><a href="#cb1-5"></a> q,</span>
<span id="cb1-6"><a href="#cb1-6"></a> myWidgetOutput,</span>
<span id="cb1-7"><a href="#cb1-7"></a> <span class="dt">quoted =</span> <span class="ot">TRUE</span>,</span>
<span id="cb1-8"><a href="#cb1-8"></a> <span class="dt">cacheHint =</span> <span class="kw">list</span>(<span class="dt">label =</span> <span class="st">"myWidget"</span>, <span class="dt">userQuo =</span> q)</span>
<span id="cb1-9"><a href="#cb1-9"></a> )</span>
<span id="cb1-10"><a href="#cb1-10"></a>}</span></code></pre><p></p></div>
<p>If your <code>render</code> function sets any internal state, you may find it useful
in your call to <code><a href="createRenderFunction.html">createRenderFunction()</a></code> to use
the <code>cacheWriteHook</code> and/or <code>cacheReadHook</code> parameters. These hooks are
@@ -339,7 +357,7 @@ in order to work properly.</p>
<p>When <code>bindCache()</code> is used with <code><a href="renderPlot.html">renderPlot()</a></code>, the <code>height</code> and <code>width</code>
passed to the original <code><a href="renderPlot.html">renderPlot()</a></code> are ignored. They are superseded by
<code>sizePolicy</code> argument passed to `bindCache. The default is:</p>
<p></p><div class="sourceCode"><pre><code></code></pre><p></p></div>
<p></p><div class="sourceCode"><pre><code><span id="cb1-1"><a href="#cb1-1"></a>sizePolicy =<span class="st"> </span><span class="kw">sizeGrowthRatio</span>(<span class="dt">width =</span> <span class="dv">400</span>, <span class="dt">height =</span> <span class="dv">400</span>, <span class="dt">growthRate =</span> <span class="fl">1.2</span>)</span></code></pre><p></p></div>
<p><code>sizePolicy</code> must be a function that takes a two-element numeric vector as
input, representing the width and height of the <code>&lt;img&gt;</code> element in the
browser window, and it must return a two-element numeric vector, representing
@@ -461,7 +479,7 @@ See <code><a href="sizeGrowthRatio.html">sizeGrowthRatio()</a></code> for more i
</div>
<div class="pkgdown">
<p></p><p>Site built with <a href="https://pkgdown.r-lib.org/" class="external-link">pkgdown</a> 2.0.3.</p>
<p></p><p>Site built with <a href="https://pkgdown.r-lib.org/" class="external-link">pkgdown</a> 2.0.4.</p>
</div>
</footer></div>