Skip to contents

Generates a 'Lottie' animation for use within a 'shiny' application.

Usage

lottie_animation(
  path,
  name,
  loop = TRUE,
  autoplay = TRUE,
  renderer = "svg",
  width = "400px",
  height = "400px",
  ...,
  session = shiny::getDefaultReactiveDomain()
)

Arguments

path

Either a URL or local file path (see Note).

name

A character string specifying the name to give to the animation.

loop

Logical indicating whether the animation should loop.

autoplay

Logical indicating whether the animation should autoplay.

renderer

The renderer to use for the animation, either "svg", "canvas", or "html".

width

The width of the animation container. This is validated using validateCssUnit.

height

The height of the animation container. This is validated using validateCssUnit.

...

Additional animation options, including:

speed

A numeric specifying the desired animation speed.

direction

Either 1 for forward playback or -1 for reverse playback.

setSubFrame

A logical value specifying whether a 'Lottie' animation should loop (TRUE) or not (FALSE).

playSegments

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).

session

The 'shiny' session object. Defaults to the current reactive domain.

Value

A list containing the following elements:

div

An HTML div element serving as the 'Lottie' animation container.

script

A script tag containing the 'JavaScript' to initialise the 'Lottie' animation.

Note

When using a local file path, you may need to use addResourcePath.

Examples

if (FALSE) { # interactive()
library(shiny)
library(shinyLottie)

ui <- fluidPage(
  include_lottie(),
  lottie_animation(
    path = "shinyLottie/example.json",
    name = "my_animation"
  )
)

server <- function(input, output, session) {}

shinyApp(ui, server)
}