View source: R/lottie_removeEventListener.R
lottie_removeEventListener | R Documentation |
Removes an event listener from a 'Lottie' animation within a 'shiny' application.
lottie_removeEventListener(
name,
event,
target,
functionName = NULL,
session = shiny::getDefaultReactiveDomain()
)
name |
A character string specifying the name of the 'Lottie' animation. |
event |
The event to listen for (e.g. " |
target |
The target for the event listener, either |
functionName |
Optional name of the event handler function to remove. Should only be used if a |
session |
The 'shiny' session object. Defaults to the current reactive domain. |
When run within a reactive context, sends a custom session message "lottie_js_runJS"
containing the function arguments.
This function is called for a side effect, and so there is no return value.
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.