Generate 'Lottie' Animation for a 'shiny' application
lottie_animation.RdGenerates 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:
speedA numeric specifying the desired animation speed.
directionEither
1for forward playback or-1for reverse playback.setSubFrameA logical value specifying whether a 'Lottie' animation should loop (
TRUE) or not (FALSE).playSegmentsA numeric vector or list of numeric vectors indicating the segment(s) to be played.
forceFlagLogical 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:
divAn HTML
divelement serving as the 'Lottie' animation container.scriptA
scripttag 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)
}