Files
shiny/reference/shinyAppTemplate.html
2024-09-25 22:54:28 +00:00

153 lines
11 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>Generate a Shiny application from a template — shinyAppTemplate • 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="Generate a Shiny application from a template — shinyAppTemplate"><meta property="og:description" content="This function populates a directory with files for a Shiny application."><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.9.1.9000</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>Generate a Shiny application from a template</h1>
<small class="dont-index">Source: <a href="https://github.com/rstudio/shiny/blob/main/R/app_template.R" class="external-link"><code>R/app_template.R</code></a></small>
<div class="hidden name"><code>shinyAppTemplate.Rd</code></div>
</div>
<div class="ref-description">
<p>This function populates a directory with files for a Shiny application.</p>
</div>
<div id="ref-usage">
<div class="sourceCode"><pre class="sourceCode r"><code><span><span class="fu">shinyAppTemplate</span><span class="op">(</span>path <span class="op">=</span> <span class="cn">NULL</span>, examples <span class="op">=</span> <span class="st">"default"</span>, dryrun <span class="op">=</span> <span class="cn">FALSE</span><span class="op">)</span></span></code></pre></div>
</div>
<div id="arguments">
<h2>Arguments</h2>
<dl><dt id="arg-path">path<a class="anchor" aria-label="anchor" href="#arg-path"></a></dt>
<dd><p>Path to create new shiny application template.</p></dd>
<dt id="arg-examples">examples<a class="anchor" aria-label="anchor" href="#arg-examples"></a></dt>
<dd><p>Either one of "default", "ask", "all", or any combination of
"app", "rdir", "module", and "tests". In an
interactive session, "default" falls back to "ask"; in a non-interactive
session, "default" falls back to "all". With "ask", this function will
prompt the user to select which template items will be added to the new app
directory. With "all", all template items will be added to the app
directory.</p></dd>
<dt id="arg-dryrun">dryrun<a class="anchor" aria-label="anchor" href="#arg-dryrun"></a></dt>
<dd><p>If <code>TRUE</code>, don't actually write any files; just print out which
files would be written.</p></dd>
</dl></div>
<div id="details">
<h2>Details</h2>
<p>In an interactive R session, this function will, by default, prompt the user
to select which components to add to the application. Choices are</p>
<p></p><div class="sourceCode"><pre><code><span id="cb1-1"><a href="#cb1-1" tabindex="-1"></a><span class="dv">1</span><span class="sc">:</span> All</span>
<span id="cb1-2"><a href="#cb1-2" tabindex="-1"></a><span class="dv">2</span><span class="sc">:</span> app.R <span class="sc">:</span> Main application file</span>
<span id="cb1-3"><a href="#cb1-3" tabindex="-1"></a><span class="dv">3</span><span class="sc">:</span> R<span class="sc">/</span>example.R <span class="sc">:</span> Helper file with R code</span>
<span id="cb1-4"><a href="#cb1-4" tabindex="-1"></a><span class="dv">4</span><span class="sc">:</span> R<span class="sc">/</span>example<span class="sc">-</span>module.R <span class="sc">:</span> Example module</span>
<span id="cb1-5"><a href="#cb1-5" tabindex="-1"></a><span class="dv">5</span><span class="sc">:</span> tests<span class="sc">/</span>testthat<span class="sc">/</span> <span class="er">:</span> Tests using the testthat and shinytest2 package</span></code></pre><p></p></div>
<p>If option 1 is selected, the full example application including the
following files and directories is created:</p>
<p></p><div class="sourceCode"><pre><code><span id="cb1-1"><a href="#cb1-1" tabindex="-1"></a>appdir<span class="sc">/</span></span>
<span id="cb1-2"><a href="#cb1-2" tabindex="-1"></a><span class="er">|</span><span class="sc">-</span> app.R</span>
<span id="cb1-3"><a href="#cb1-3" tabindex="-1"></a><span class="sc">|-</span> R</span>
<span id="cb1-4"><a href="#cb1-4" tabindex="-1"></a><span class="sc">|</span> <span class="er">|</span><span class="sc">-</span> example<span class="sc">-</span>module.R</span>
<span id="cb1-5"><a href="#cb1-5" tabindex="-1"></a><span class="sc">|</span> <span class="st">`</span><span class="at">- example.R</span></span>
<span id="cb1-6"><a href="#cb1-6" tabindex="-1"></a><span class="st">`</span><span class="sc">-</span> tests</span>
<span id="cb1-7"><a href="#cb1-7" tabindex="-1"></a> <span class="sc">|-</span> testthat.R</span>
<span id="cb1-8"><a href="#cb1-8" tabindex="-1"></a> <span class="st">`</span><span class="at">- testthat</span></span>
<span id="cb1-9"><a href="#cb1-9" tabindex="-1"></a><span class="at"> |- setup-shinytest2.R</span></span>
<span id="cb1-10"><a href="#cb1-10" tabindex="-1"></a><span class="at"> |- test-examplemodule.R</span></span>
<span id="cb1-11"><a href="#cb1-11" tabindex="-1"></a><span class="at"> |- test-server.R</span></span>
<span id="cb1-12"><a href="#cb1-12" tabindex="-1"></a><span class="at"> |- test-shinytest2.R</span></span>
<span id="cb1-13"><a href="#cb1-13" tabindex="-1"></a><span class="at"> </span><span class="st">`</span><span class="sc">-</span> test<span class="sc">-</span>sort.R</span></code></pre><p></p></div>
<p>Some notes about these files:</p><ul><li><p><code>app.R</code> is the main application file.</p></li>
<li><p>All files in the <code>R/</code> subdirectory are automatically sourced when the
application is run.</p></li>
<li><p><code>R/example.R</code> and <code>R/example-module.R</code> are automatically sourced when
the application is run. The first contains a function <code>lexical_sort()</code>,
and the second contains code for module created by the
<code><a href="moduleServer.html">moduleServer()</a></code> function, which is used in the application.</p></li>
<li><p><code>tests/</code> contains various tests for the application. You may
choose to use or remove any of them. They can be executed by the
<code><a href="runTests.html">runTests()</a></code> function.</p></li>
<li><p><code>tests/testthat.R</code> is a test runner for test files in the
<code>tests/testthat/</code> directory using the
<a href="https://rstudio.github.io/shinytest2/reference/test_app.html" class="external-link">shinytest2</a>
package.</p></li>
<li><p><code>tests/testthat/setup-shinytest2.R</code> is setup file to source your <code>./R</code> folder into the testing environment.</p></li>
<li><p><code>tests/testthat/test-examplemodule.R</code> is a test for an application's module server function.</p></li>
<li><p><code>tests/testthat/test-server.R</code> is a test for the application's server code</p></li>
<li><p><code>tests/testthat/test-shinytest2.R</code> is a test that uses the
<a href="https://rstudio.github.io/shinytest2/" class="external-link">shinytest2</a> package to do
snapshot-based testing.</p></li>
<li><p><code>tests/testthat/test-sort.R</code> is a test for a supporting function in the <code>R/</code> directory.</p></li>
</ul></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.1.</p>
</div>
</footer></div>
</body></html>