Files
shiny/reference/actionButton.html
2025-12-09 21:34:58 +00:00

186 lines
14 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!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>Action button/link — actionButton • 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="Action button/link — actionButton"><meta property="og:description" content="Creates an action button or link whose value is initially zero, and increments by one
each time it is pressed."><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.12.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>Action button/link</h1>
<small class="dont-index">Source: <a href="https://github.com/rstudio/shiny/blob/main/R/input-action.R" class="external-link"><code>R/input-action.R</code></a></small>
<div class="hidden name"><code>actionButton.Rd</code></div>
</div>
<div class="ref-description">
<p>Creates an action button or link whose value is initially zero, and increments by one
each time it is pressed.</p>
</div>
<div id="ref-usage">
<div class="sourceCode"><pre class="sourceCode r"><code><span><span class="fu">actionButton</span><span class="op">(</span><span class="va">inputId</span>, <span class="va">label</span>, icon <span class="op">=</span> <span class="cn">NULL</span>, width <span class="op">=</span> <span class="cn">NULL</span>, disabled <span class="op">=</span> <span class="cn">FALSE</span>, <span class="va">...</span><span class="op">)</span></span>
<span></span>
<span><span class="fu">actionLink</span><span class="op">(</span><span class="va">inputId</span>, <span class="va">label</span>, icon <span class="op">=</span> <span class="cn">NULL</span>, <span class="va">...</span><span class="op">)</span></span></code></pre></div>
</div>
<div id="arguments">
<h2>Arguments</h2>
<dl><dt id="arg-inputid">inputId<a class="anchor" aria-label="anchor" href="#arg-inputid"></a></dt>
<dd><p>The <code>input</code> slot that will be used to access the value.</p></dd>
<dt id="arg-label">label<a class="anchor" aria-label="anchor" href="#arg-label"></a></dt>
<dd><p>The contents of the button or linkusually a text label, but
you could also use any other HTML, like an image.</p></dd>
<dt id="arg-icon">icon<a class="anchor" aria-label="anchor" href="#arg-icon"></a></dt>
<dd><p>An optional <code><a href="icon.html">icon()</a></code> to appear on the button.</p></dd>
<dt id="arg-width">width<a class="anchor" aria-label="anchor" href="#arg-width"></a></dt>
<dd><p>The width of the input, e.g. <code>'400px'</code>, or <code>'100%'</code>;
see <code><a href="https://rstudio.github.io/htmltools/reference/validateCssUnit.html" class="external-link">validateCssUnit()</a></code>.</p></dd>
<dt id="arg-disabled">disabled<a class="anchor" aria-label="anchor" href="#arg-disabled"></a></dt>
<dd><p>If <code>TRUE</code>, the button will not be clickable. Use
<code><a href="updateActionButton.html">updateActionButton()</a></code> to dynamically enable/disable the button.</p></dd>
<dt id="arg--">...<a class="anchor" aria-label="anchor" href="#arg--"></a></dt>
<dd><p>Named attributes to be applied to the button or link.</p></dd>
</dl></div>
<div id="server-value">
<h2>Server value</h2>
<p>An integer of class <code>"shinyActionButtonValue"</code>. This class differs from
ordinary integers in that a value of 0 is considered "falsy".
This implies two things:</p><ul><li><p>Event handlers (e.g., <code><a href="observeEvent.html">observeEvent()</a></code>, <code><a href="observeEvent.html">eventReactive()</a></code>) won't execute on initial load.</p></li>
<li><p>Input validation (e.g., <code><a href="req.html">req()</a></code>, <code><a href="validate.html">need()</a></code>) will fail on initial load.</p></li>
</ul></div>
<div id="see-also">
<h2>See also</h2>
<div class="dont-index"><p><code><a href="observeEvent.html">observeEvent()</a></code> and <code><a href="observeEvent.html">eventReactive()</a></code></p>
<p>Other input elements:
<code><a href="checkboxGroupInput.html">checkboxGroupInput()</a></code>,
<code><a href="checkboxInput.html">checkboxInput()</a></code>,
<code><a href="dateInput.html">dateInput()</a></code>,
<code><a href="dateRangeInput.html">dateRangeInput()</a></code>,
<code><a href="fileInput.html">fileInput()</a></code>,
<code><a href="numericInput.html">numericInput()</a></code>,
<code><a href="passwordInput.html">passwordInput()</a></code>,
<code><a href="radioButtons.html">radioButtons()</a></code>,
<code><a href="selectInput.html">selectInput()</a></code>,
<code><a href="sliderInput.html">sliderInput()</a></code>,
<code><a href="submitButton.html">submitButton()</a></code>,
<code><a href="textAreaInput.html">textAreaInput()</a></code>,
<code><a href="textInput.html">textInput()</a></code>,
<code><a href="varSelectInput.html">varSelectInput()</a></code></p></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="sliderInput.html">sliderInput</a></span><span class="op">(</span><span class="st">"obs"</span>, <span class="st">"Number of observations"</span>, <span class="fl">0</span>, <span class="fl">1000</span>, <span class="fl">500</span><span class="op">)</span>,</span></span>
<span class="r-in"><span> <span class="fu">actionButton</span><span class="op">(</span><span class="st">"goButton"</span>, <span class="st">"Go!"</span>, class <span class="op">=</span> <span class="st">"btn-success"</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">"distPlot"</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="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">distPlot</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="co"># Take a dependency on input$goButton. This will run once initially,</span></span></span>
<span class="r-in"><span> <span class="co"># because the value changes from NULL to 0.</span></span></span>
<span class="r-in"><span> <span class="va">input</span><span class="op">$</span><span class="va">goButton</span></span></span>
<span class="r-in"><span></span></span>
<span class="r-in"><span> <span class="co"># Use isolate() to avoid dependency on input$obs</span></span></span>
<span class="r-in"><span> <span class="va">dist</span> <span class="op">&lt;-</span> <span class="fu"><a href="isolate.html">isolate</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/stats/Normal.html" class="external-link">rnorm</a></span><span class="op">(</span><span class="va">input</span><span class="op">$</span><span class="va">obs</span><span class="op">)</span><span class="op">)</span></span></span>
<span class="r-in"><span> <span class="fu"><a href="https://rdrr.io/r/graphics/hist.html" class="external-link">hist</a></span><span class="op">(</span><span class="va">dist</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></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="co">## Example of adding extra class values</span></span></span>
<span class="r-in"><span><span class="fu">actionButton</span><span class="op">(</span><span class="st">"largeButton"</span>, <span class="st">"Large Primary Button"</span>, class <span class="op">=</span> <span class="st">"btn-primary btn-lg"</span><span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> &lt;button class="btn btn-default action-button btn-primary btn-lg" id="largeButton" type="button"&gt;</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> &lt;span class="action-label"&gt;Large Primary Button&lt;/span&gt;</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> &lt;/button&gt;</span>
<span class="r-in"><span><span class="fu">actionLink</span><span class="op">(</span><span class="st">"infoLink"</span>, <span class="st">"Information Link"</span>, class <span class="op">=</span> <span class="st">"btn-info"</span><span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> &lt;a class="action-button action-link btn-info" href="#" id="infoLink"&gt;</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> &lt;span class="action-label"&gt;Information Link&lt;/span&gt;</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> &lt;/a&gt;</span>
<span class="r-in"><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, Garrick Aden-Buie, 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.2.0.</p>
</div>
</footer></div>
</body></html>