Files
shiny/reference/brushedPoints.html
2022-06-14 14:23:43 +00:00

216 lines
12 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>Find rows of data selected on an interactive plot. — brushedPoints • shiny</title><!-- favicons --><link rel="icon" type="image/png" sizes="16x16" href="../favicon-16x16.png"><link rel="icon" type="image/png" sizes="32x32" href="../favicon-32x32.png"><link rel="apple-touch-icon" type="image/png" sizes="180x180" href="../apple-touch-icon.png"><link rel="apple-touch-icon" type="image/png" sizes="120x120" href="../apple-touch-icon-120x120.png"><link rel="apple-touch-icon" type="image/png" sizes="76x76" href="../apple-touch-icon-76x76.png"><link rel="apple-touch-icon" type="image/png" sizes="60x60" href="../apple-touch-icon-60x60.png"><!-- jquery --><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></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="Find rows of data selected on an interactive plot. — brushedPoints"><meta property="og:description" content="brushedPoints() returns rows from a data frame which are under a brush.
nearPoints() returns rows from a data frame which are near a click, hover,
or double-click. Alternatively, set allRows = TRUE to return all rows from
the input data with an additional column selected_ that indicates which
rows of the would be selected."><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.7.1.9003</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>Find rows of data selected on an interactive plot.</h1>
<small class="dont-index">Source: <a href="https://github.com/rstudio/shiny/blob/HEAD/R/image-interact.R" class="external-link"><code>R/image-interact.R</code></a></small>
<div class="hidden name"><code>brushedPoints.Rd</code></div>
</div>
<div class="ref-description">
<p><code>brushedPoints()</code> returns rows from a data frame which are under a brush.
<code>nearPoints()</code> returns rows from a data frame which are near a click, hover,
or double-click. Alternatively, set <code>allRows = TRUE</code> to return all rows from
the input data with an additional column <code>selected_</code> that indicates which
rows of the would be selected.</p>
</div>
<div id="ref-usage">
<div class="sourceCode"><pre class="sourceCode r"><code><span class="fu">brushedPoints</span><span class="op">(</span>
<span class="va">df</span>,
<span class="va">brush</span>,
xvar <span class="op">=</span> <span class="cn">NULL</span>,
yvar <span class="op">=</span> <span class="cn">NULL</span>,
panelvar1 <span class="op">=</span> <span class="cn">NULL</span>,
panelvar2 <span class="op">=</span> <span class="cn">NULL</span>,
allRows <span class="op">=</span> <span class="cn">FALSE</span>
<span class="op">)</span>
<span class="fu">nearPoints</span><span class="op">(</span>
<span class="va">df</span>,
<span class="va">coordinfo</span>,
xvar <span class="op">=</span> <span class="cn">NULL</span>,
yvar <span class="op">=</span> <span class="cn">NULL</span>,
panelvar1 <span class="op">=</span> <span class="cn">NULL</span>,
panelvar2 <span class="op">=</span> <span class="cn">NULL</span>,
threshold <span class="op">=</span> <span class="fl">5</span>,
maxpoints <span class="op">=</span> <span class="cn">NULL</span>,
addDist <span class="op">=</span> <span class="cn">FALSE</span>,
allRows <span class="op">=</span> <span class="cn">FALSE</span>
<span class="op">)</span></code></pre></div>
</div>
<div id="arguments">
<h2>Arguments</h2>
<dl><dt>df</dt>
<dd><p>A data frame from which to select rows.</p></dd>
<dt>brush, coordinfo</dt>
<dd><p>The data from a brush or click/dblclick/hover event
e.g. <code>input$plot_brush</code>, <code>input$plot_click</code>.</p></dd>
<dt>xvar, yvar</dt>
<dd><p>A string giving the name of the variable on the x or y axis.
These are only required for base graphics, and must be the name of
a column in <code>df</code>.</p></dd>
<dt>panelvar1, panelvar2</dt>
<dd><p>A string giving the name of a panel variable.
For expert use only; in most cases these will be automatically
derived from the ggplot2 spec.</p></dd>
<dt>allRows</dt>
<dd><p>If <code>FALSE</code> (the default) return a data frame containing
the selected rows. If <code>TRUE</code>, the input data frame will have a new
column, <code>selected_</code>, which indicates whether the row was selected or not.</p></dd>
<dt>threshold</dt>
<dd><p>A maximum distance (in pixels) to the pointer location.
Rows in the data frame will be selected if the distance to the pointer is
less than <code>threshold</code>.</p></dd>
<dt>maxpoints</dt>
<dd><p>Maximum number of rows to return. If <code>NULL</code> (the default),
will return all rows within the threshold distance.</p></dd>
<dt>addDist</dt>
<dd><p>If TRUE, add a column named <code>dist_</code> that contains the
distance from the coordinate to the point, in pixels. When no pointer
event has yet occurred, the value of <code>dist_</code> will be <code>NA</code>.</p></dd>
</dl></div>
<div id="value">
<h2>Value</h2>
<p>A data frame based on <code>df</code>, containing the observations selected by the
brush or near the click event. For <code>nearPoints()</code>, the rows will be sorted
by distance to the event.</p>
<p>If <code>allRows = TRUE</code>, then all rows will returned, along with a new
<code>selected_</code> column that indicates whether or not the point was selected.
The output from <code>nearPoints()</code> will no longer be sorted, but you can
set <code>addDist = TRUE</code> to get an additional column that gives the pixel
distance to the pointer.</p>
</div>
<div id="ggplot-">
<h2>ggplot2</h2>
<p>For plots created with ggplot2, it is not necessary to specify the
column names to <code>xvar</code>, <code>yvar</code>, <code>panelvar1</code>, and <code>panelvar2</code> as that
information can be automatically derived from the plot specification.</p>
<p>Note, however, that this will not work if you use a computed column, like
<code>aes(speed/2, dist))</code>. Instead, we recommend that you modify the data
first, and then make the plot with "raw" columns in the modified data.</p>
</div>
<div id="brushing">
<h2>Brushing</h2>
<p>If x or y column is a factor, then it will be coerced to an integer vector.
If it is a character vector, then it will be coerced to a factor and then
integer vector. This means that the brush will be considered to cover a
given character/factor value when it covers the center value.</p>
<p>If the brush is operating in just the x or y directions (e.g., with
<code>brushOpts(direction = "x")</code>, then this function will filter out points
using just the x or y variable, whichever is appropriate.</p>
</div>
<div id="see-also">
<h2>See also</h2>
<div class="dont-index"><p><code><a href="plotOutput.html">plotOutput()</a></code> for example usage.</p></div>
</div>
<div id="ref-examples">
<h2>Examples</h2>
<div class="sourceCode"><pre class="sourceCode r"><code><span class="r-in"><span class="kw">if</span> <span class="op">(</span><span class="cn">FALSE</span><span class="op">)</span> <span class="op">{</span></span>
<span class="r-in"><span class="co"># Note that in practice, these examples would need to go in reactives</span></span>
<span class="r-in"><span class="co"># or observers.</span></span>
<span class="r-in"></span>
<span class="r-in"><span class="co"># This would select all points within 5 pixels of the click</span></span>
<span class="r-in"><span class="fu">nearPoints</span><span class="op">(</span><span class="va">mtcars</span>, <span class="va">input</span><span class="op">$</span><span class="va">plot_click</span><span class="op">)</span></span>
<span class="r-in"></span>
<span class="r-in"><span class="co"># Select just the nearest point within 10 pixels of the click</span></span>
<span class="r-in"><span class="fu">nearPoints</span><span class="op">(</span><span class="va">mtcars</span>, <span class="va">input</span><span class="op">$</span><span class="va">plot_click</span>, threshold <span class="op">=</span> <span class="fl">10</span>, maxpoints <span class="op">=</span> <span class="fl">1</span><span class="op">)</span></span>
<span class="r-in"></span>
<span class="r-in"><span class="op">}</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.</p>
</div>
<div class="pkgdown">
<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>
</body></html>