Description Usage Arguments Details See Also Examples
View source: R/image-interact.R
This function returns rows from a data frame which are near a click, hover, or
double-click, when used with plotOutput
. The rows will be sorted
by their distance to the mouse event.
1 2 3 |
df |
A data frame from which to select rows. |
coordinfo |
The data from a mouse event, such as |
xvar |
A string with the name of the variable on the x or y axis.
This must also be the name of a column in |
yvar |
A string with the name of the variable on the x or y axis.
This must also be the name of a column in |
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
|
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
|
threshold |
A maxmimum distance to the click point; rows in the data
frame where the distance to the click is less than |
maxpoints |
Maximum number of rows to return. If NULL (the default), return all rows that are within the threshold distance. |
addDist |
If TRUE, add a column named |
allRows |
If |
It is also possible for this function to return all rows from the input data
frame, but with an additional column selected_
, which indicates which
rows of the input data frame are selected by the brush (TRUE
for
selected, FALSE
for not-selected). This is enabled by setting
allRows=TRUE
option. If this is used, the resulting data frame will not
be sorted by distance to the mouse event.
The xvar
, yvar
, panelvar1
, and 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
plot(x=cars$speed, y=cars$dist)
, and your click variable is named
"cars_click"
, then you would use nearPoints(cars,
input$cars_brush, "speed", "dist")
.
plotOutput
for more examples.
1 2 3 4 5 6 7 8 9 10 11 12 | ## Not run:
# 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, maxpoints = 1)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.