Learn R Programming

shinyLottie (version 1.0.0)

lottie_playSegments: Play Specific Segments of a 'Lottie' Animation

Description

Play specific segments of a 'Lottie' animation.

Usage

lottie_playSegments(
  segments,
  forceFlag = TRUE,
  name = "all",
  session = shiny::getDefaultReactiveDomain()
)

Value

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

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.

Details

Sends a custom session message "lottie_js_playSegments" containing the function arguments.

See Also

lottie_animation_methods for similar methods.

Examples

Run this code
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)
}

Run the code above in your browser using DataLab