‘shinyLottie’ is an R package that allows users to easily integrate and control ‘Lottie’ animations within ‘shiny’ applications, without the need for idiosyncratic expression or use of ‘JavaScript’.
This document introduces the most basic implementation of this package using the following functions:
include_lottie()
is required in order for
‘shinyLottie’ functions to work
lottie_animation()
generates a ‘Lottie’ animation
object that can be inserted into a ‘shiny’ app’s UI
lottie_button()
converts a ‘Lottie’ animation object
into a button; this is behaviourally identical to
actionButton()
The following example demonstrates how to produce a simple ‘shiny’ app that includes a ‘Lottie’ animation.
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)
This relies on the use of two functions within the UI:
include_lottie()
loads the necessary ‘JavaScript’ to
enable ‘Lottie’ functionality
lottie_animation()
generates a ‘Lottie’ animation
sourced from the supplied path
argument
There are two types of path
that can be used to
reference a ‘Lottie’ animation:
A local file path to a JSON file - the path
used in
the above app references an example animation that is installed
alongside ‘shinyLottie’
A URL for web-hosted JSON files (i.e. LottieFiles asset link or LottieLab JSON URL)
lottie_animation()
also requires that we provide a
name
, which we can then reference when updating the
animation during ‘shiny’ runtime. This process, along with further
arguments that can be supplied to fine-tune playback behaviour, are
explained in vignette("Controlling-Animations")
.