removeEvent: Remove an event that was added to an element

Description Usage Arguments Event types See Also Examples

View source: R/onevent.R

Description

This function can be used to revert the action of onclick or onevent.

Usage

1
removeEvent(event, id, asis = FALSE)

Arguments

event

Either an event type (see below for a list of event types) or an event ID (the return value from onclick or onevent). If an event type is provided (eg. "hover"), then all events of this type attached to the given element will be removed. If an event ID is provided, then only that specific event will be removed. See examples for clarification.

id

The ID of the element/Shiny tag. Must match the ID used in onclick or onevent.

asis

If TRUE, use the ID as-is even when inside a module (instead of adding the namespace prefix to the ID).

Event types

Any standard mouse or keyboard events that are supported by JQuery can be used. The standard list of events that can be used is: click, dblclick, hover, mousedown, mouseenter, mouseleave, mousemove, mouseout, mouseover, mouseup, keydown, keypress, keyup. You can also use any other non standard events that your browser supports or with the use of plugins (for example, there is a mousewheel plugin that you can use to listen to mousewheel events).

See Also

onclick, onevent

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
if (interactive()) {
  library(shiny)

  shinyApp(
    ui = fluidPage(
      useShinyjs(),  # Set up shinyjs
      p(id = "myel", "Hover over me to see the date, the time, and a random integer"),
      actionButton("remove_date", "Remove date hover event"),
      actionButton("remove_all", "Remove all hover events")
    ),
    server = function(input, output) {
      onevent("hover", "myel", print(format(Sys.time(), "%H:%M:%S")))
      onevent("hover", "myel", print(sample(100, 1)), add = TRUE)
      date_event_id <- onevent("hover", "myel", print(as.character(Sys.Date())), add = TRUE)

      observeEvent(input$remove_all, {
        removeEvent("hover", "myel")
      })
      observeEvent(input$remove_date, {
        removeEvent(date_event_id, "myel")
      })
    }
  )
}

shinyjs documentation built on Dec. 23, 2021, 5:06 p.m.