Skip to contents

Removes an event listener from a 'Lottie' animation within a 'shiny' application.

Usage

lottie_removeEventListener(
  name,
  event,
  target,
  functionName = NULL,
  session = shiny::getDefaultReactiveDomain()
)

Arguments

name

A character string specifying the name of the 'Lottie' animation.

event

The event to listen for (e.g. "mouseenter", "mouseleave" etc.).

target

The target for the event listener, either "animation" or "container".

functionName

Optional name of the event handler function to remove. Should only be used if a functionName was specified when calling lottie_addEventListener.

session

The 'shiny' session object. Defaults to the current reactive domain.

Value

This function is called for a side effect, and so there is no return value.

Details

When run within a reactive context, sends a custom session message "lottie_js_runJS" containing the function arguments.

Examples

if (FALSE) { # interactive()
library(shiny)
library(shinyLottie)

ui <- fluidPage(
  include_lottie(),
  # Create an 'animation' event that updates the 'playCount' input value
  # value after each loop
  lottie_animation(
    path = "shinyLottie/example.json",
    name = "my_animation"
  ) |>
    lottie_addEventListener(
      event = "loopComplete",
      target = "animation",
      custom_js = "Shiny.setInputValue('playCount',
      lottieInstances.my_animation.playCount, {priority: 'event'});"
    ),
  actionButton("removeEventListener", "Remove Event Listener")
)

server <- function(input, output, session) {
  # Notifications demonstrate that eventListener is active
  observeEvent(input$playCount, {
    showNotification(paste("Animation played", input$playCount, "times"), duration = 1)
  })

  # Removing the event listener ceases the notifications
  observeEvent(input$removeEventListener, {
    lottie_removeEventListener(name = "my_animation", event = "loopComplete",
                               target = "animation")
  })
}

shinyApp(ui, server)
}