MyNixOS website logo
Description

Animate Shiny and R Markdown Content when it Comes into View.

Animate Shiny and R Markdown content when it comes into view using 'animate-css' effects thanks to 'jQuery AniView'.

CRANstatus pipelinestatus

aniview

Animate Shiny and R Markdown content when it comes into view

The package aniview allows to animate Shiny and R Markdown content when it comes into view using animate-css thanks to AniView.

Installation

Install the package from Github.

# install.packages("remotes")
remotes::install_github("lgnbhl/aniview")

Shiny

In order to use aniview, you must first call use_aniview() in the apps’ UI.

Then simply apply aniview() to any shiny element with an animation listed on the animate-css website.

library(shiny)
library(ggplot2)
library(aniview)

ui <- function(){
  fluidPage(
    aniview::use_aniview(), # add use_aniview() in the UI
    aniview(h1("Shiny with AniView", align = "center"), animation = "fadeInUp"),
    br(),
    aniview(plotOutput("plot"), animation = "zoomIn")
  )
}

server <- function(input, output, session){
  output$plot <- renderPlot({
    ggplot(mpg, aes(displ, hwy, colour = class)) + 
      geom_point()
  })
}

shinyApp(ui, server)

Htmlwidgets

The function aniview() doesn’t work directly with htmlwidgets.

The solution is to put the htmlwidget inside a container and animate it.

Below an example animating the box() from shinydashboard in order to use plotly.

library(shinydashboard)
library(plotly)

ui <- dashboardPage(
  dashboardHeader(title = "Basic dashboard"),
  dashboardSidebar(),
  dashboardBody(
    use_aniview(), # use_aniview() should be inside the body element
    fluidRow(
      aniview(box(plotlyOutput("plotly")), animation = "slideInLeft"),
    )
  )
)

server <- function(input, output) {
  output$plotly <- renderPlotly({
    gg <- ggplot(mpg, aes(displ, hwy, colour = class)) + 
      geom_point()
    ggplotly(gg)
  })
}

shinyApp(ui, server)

R Markdown

To animate a element of a R Markdown document, you must first call use_aniview() inside a R code chunk with {r, echo = FALSE} so the code will not be shown in the final document.

`
``{r, echo = FALSE}
aniview::use_aniview()
`
``

Then you can animate any content of your R Markdown document using the ::: markers of the rmarkdown package followed by {.aniview data-av-animation="ANIMATE-CSS EFFECT"}. The animate-css effects are listed here.

Below an example with the “slideInUp” effect.

::: {.aniview data-av-animation="slideInUp"}
This element will be animated.
:::

You can learn more about the CSS class markers in the Custom block chapter of the R Markdown Cookbook from Yihui Xie.

Xaringan presentation

xaringan is a package for creating slideshows with remark.js using R Markdown. You can take a look at its introductory presentation.

You can easily animate a slide using the “animated” class of animate-css with any animation effect.

Below is a minimal example.

-
--
title: "Presentation Ninja"
subtitle: "with xaringan"
output:
  xaringan::moon_reader:
    lib_dir: libs
-
--

`
``{r, echo = FALSE}
aniview::use_aniview()
`
``

# A normal slide

-
--
class: animated, bounceInDown

# An animated slide
Metadata

Version

0.1.0

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows