plotOutput. The rows will be sorted
by their distance to the mouse event.nearPoints(df, coordinfo, xvar = NULL, yvar = NULL, panelvar1 = NULL,
panelvar2 = NULL, threshold = 5, maxpoints = NULL, addDist = FALSE,
allRows = FALSE)input$plot_click.df. If absent, then this
function will try to infer the variable from the brush (only works for
ggplot2).df. If absent, then this
function will try to infer the variable from the brush (only works for
ggplot2).cyl, then you can use "cyl" here. However, specifying the
panel variable should not be necessary with ggplocyl, then you can use "cyl" here. However, specifying the
panel variable should not be necessary with ggplothreshold will be
returned.dist_ that contains the
distance from the coordinate to the point, in pixels. When no mouse event
has yet occured, the value of dist_ will be NA.FALSE (the default) return a data frame containing
the selected rows. If TRUE, the input data frame will have a new
column, selected_, which indicates whether the row was inside the
selected by the mouse event 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.# 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)Run the code above in your browser using DataLab