Play Specific Segments of a 'Lottie' Animation
lottie_playSegments.Rd
Play specific segments of a 'Lottie' animation.
Usage
lottie_playSegments(
segments,
forceFlag = TRUE,
name = "all",
session = shiny::getDefaultReactiveDomain()
)
Arguments
- segments
A numeric vector or list of numeric vectors indicating the segment(s) to be played.
- forceFlag
Logical value indicating whether to force the animation to play the specified segments immediately (
TRUE
) or wait until the current animation completes (FALSE
).- name
A character string specifying the name of the 'Lottie' animation to control. The default of "
all
" will control all animations within the 'shiny' application.- session
The 'shiny' session object. Defaults to the current reactive domain.
Note
To play a single segment, segments
should be a numeric vector of length 2 that represents the start and end frames.
To play multiple segments, provide a list containing multiple numeric vectors of length 2. Note that if the animation
is set to be looped, only the final segment will be repeated.
See also
lottie_animation_methods
for similar methods.
Examples
if (FALSE) { # interactive()
library(shiny)
library(shinyLottie)
ui <- fluidPage(
include_lottie(),
lottie_animation(
path = "shinyLottie/example.json",
name = "my_animation",
loop = FALSE,
speed = 0.5 # Slowed to make effects clearer
),
actionButton("playSegments1", "Play Frames 1 - 10"),
# Will not work if animation has less than 40 frames
actionButton("playSegments2", "Play Frames 1 - 10 and 30 - 40")
)
server <- function(input, output, session) {
observeEvent(input$playSegments1, {
lottie_playSegments(segments = c(1, 10), forceFlag = TRUE,
name = "my_animation")
})
observeEvent(input$playSegments2, {
lottie_playSegments(segments = list(c(1, 10), c(30, 40)),
forceFlag = TRUE, name = "my_animation")
})
}
shinyApp(ui, server)
}