View source: R/lottie_playSegments.R
| lottie_playSegments | R Documentation | 
Play specific segments of a 'Lottie' animation.
lottie_playSegments(
  segments,
  forceFlag = TRUE,
  name = "all",
  session = shiny::getDefaultReactiveDomain()
)
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 (  | 
name | 
 A character string specifying the name of the 'Lottie' animation to control.
The default of "  | 
session | 
 The 'shiny' session object. Defaults to the current reactive domain.  | 
Sends a custom session message "lottie_js_playSegments" containing the function arguments.
This function is called for a side effect, and so there is no return value.
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.
lottie_animation_methods for similar methods.
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.