-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
152 lines (112 loc) · 4.46 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
<!-- badges: start -->
[](https://CRAN.R-project.org/package=aniview)
[](https://cran.r-project.org/package=aniview)
[](https://github.com/lgnbhl/aniview/actions/workflows/R-CMD-check.yaml)
<!-- badges: end -->
# aniview <img src="man/figures/logo.png" align="right" width="138" />
> 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](https://daneden.github.io/animate.css/) thanks to [AniView](https://jjcosgrove.github.io/jquery-aniview/).
## Installation
Install the released version from CRAN.
```{r install cran, eval = FALSE}
install.packages("aniview")
```
To get a bug fix, or use a feature from the development version, you can install it from GitHub.
```{r install github, eval = FALSE}
# install.packages("remotes")
remotes::install_github("lgnbhl/aniview")
```
## Shiny
In order to use aniview, you must first call `use_aniview()` in the UI.
Then simply apply `aniview()` to any shiny element with an animation listed on the [animate-css website](https://daneden.github.io/animate.css/).
Here a basic example:
```{r shiny, eval = FALSE}
library(shiny)
library(tidyverse)
library(ggrepel)
library(aniview)
shinyApp(
ui = fluidPage(
align = "center",
aniview::use_aniview(), # add use_aniview() in the UI
aniview(h1("Shiny with AniView"), animation = "fadeInUp"),
HTML(rep("↓<br/><br/><br/><br/>scroll down<br/><br/>", 10)),
aniview(plotOutput("plot"), animation = "slideInLeft"),
br()
),
server = function(input, output){
output$plot <- renderPlot({
ggplot(starwars, aes(mass, height)) +
geom_point(aes(color = gender)) +
geom_label_repel(aes(label = name), size = 3) +
labs(title = "Star Wars Characters Height vs Mass")
})
}
)
```
### Htmlwidgets
The function `aniview()` doesn't work directly with [htmlwidgets](https://www.htmlwidgets.org/).
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`.
```{r htmlwidgets, eval = FALSE}
library(shiny)
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
```{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](https://daneden.github.io/animate.css/).
Below an example with the "slideInUp" effect.
```md
::: {.aniview data-av-animation="slideInUp"}
This element will be animated.
:::
```
You can learn more about the CSS class markers in the [Custom block](https://bookdown.org/yihui/rmarkdown-cookbook/custom-blocks.html) chapter of the *R Markdown Cookbook* from Yihui Xie.
### Xaringan presentation
[xaringan](https://github.com/yihui/xaringan) is a package for creating slideshows with [remark.js](https://github.com/gnab/remark) using R Markdown. You can take a look at its [introductory presentation](https://slides.yihui.name/xaringan/).
You can easily animate a slide using the "animated" class of [animate-css](https://daneden.github.io/animate.css/) with any animation effect.
Below is a minimal example.
```md
---
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
```