Use this function as the snap
parameter of overlayServer()
to enable
a simple snap-to-grid behaviour for your overlay. It will ensure your
overlays stay within the bounds of the plot, and snap both position and
width of each overlay to the specified grid.
Arguments
- anchor
The location of any specific gridline.
- step
The space between gridlines.
- min_width
(optional) Minimum width of an overlay; default (
NA
) sets tostep
. UseNULL
for no minimum.- max_width
(optional) Maximum width of an overlay; default (
NA
) sets to the largest size that accommodates the width of the overlay bounds, accounting for the grid. UseNULL
for no maximum.Note that the default values snap overlays to whole numbers.
Value
A snapping function suitable to pass to overlayServer()
as the
snap
argument.
See also
overlayServer()
, for a complete example.
Examples
server <- function(input, output) {
ov <- overlayServer("my_plot", 8, snap = snap_grid())
# further server code here . . .
}