Files
shiny/man/nearPoints.Rd
2015-04-29 13:19:46 -05:00

77 lines
3.0 KiB
R

% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/image-interact.R
\name{nearPoints}
\alias{nearPoints}
\title{Find rows of data that are near a click/hover/double-click}
\usage{
nearPoints(df, coordinfo, xvar = NULL, yvar = NULL, panelvar1 = NULL,
panelvar2 = NULL, threshold = 5, maxrows = NULL, addDist = FALSE)
}
\arguments{
\item{df}{A data frame from which to select rows.}
\item{coordinfo}{The data from a mouse event, such as \code{input$plot_click}.}
\item{xvar}{A string with the name of the variable on the x axis. This must
also be the name of a column in \code{df}. If absent, then
\code{selectBrush} will try to infer the variable from the brush (only
works for ggplot2).}
\item{yvar}{A string with the name of the variable on the y axis. This must
also be the name of a column in \code{df}. If absent, then
\code{selectBrush} will try to infer the variable from the brush (only
works for ggplot2).}
\item{panelvar1}{Each of these is a string with the name of a panel
variable. For example, if with ggplot2, you facet on a variable called
\code{cyl}, then you can use \code{"cyl"} here. However, specifying the
panel variable should not be necessary with ggplot2; Shiny should be able
to auto-detect the panel variable.}
\item{panelvar2}{Each of these is a string with the name of a panel
variable. For example, if with ggplot2, you facet on a variable called
\code{cyl}, then you can use \code{"cyl"} here. However, specifying the
panel variable should not be necessary with ggplot2; Shiny should be able
to auto-detect the panel variable.}
\item{threshold}{A maxmimum distance to the click point; rows in the data
frame where the distance to the click is less than \code{threshold} will be
returned.}
\item{maxrows}{Maximum number of rows to return. If NULL (the default),
return all rows that are within the threshold distance.}
\item{addDist}{If TRUE, add a column named \code{_dist} that contains the
distance from the coordinate to the point, in pixels.}
}
\description{
This function returns rows from a data frame which are near a click, hover,
or double-click, when used with \code{\link{plotOutput}}. The rows will be
sorted by their distance to the mouse event.
}
\details{
The \code{xvar}, \code{yvar}, \code{panelvar1}, and \code{panelvar2}
arguments specify which columns in the data correspond to the x variable, y
variable, and panel variables of the plot. For example, if your plot is
\code{plot(x=cars$speed, y=cars$dist)}, and your click variable is named
\code{"cars_click"}, then you would use \code{nearPoints(cars,
input$cars_brush, "speed", "dist")}.
}
\examples{
\dontrun{
# Note that in practice, these examples would need to go in reactives
# or observers.
# This would select all points within 5 pixels of the click
nearPoints(mtcars, input$plot_click)
# Select just the nearest point within 10 pixels of the click
nearPoints(mtcars, input$plot_click, threshold = 10, maxrows = 1)
}
}
\seealso{
\code{\link{plotOutput}} for more examples.
}