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)
}
Run the code above in your browser using DataLab