-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
133 lines (102 loc) · 3.39 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
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
### {confetti} <img src="man/figures/logo.png" align="right" height="138" />
<!-- badges: start -->
![](https://img.shields.io/badge/r%20package-%23276DC3.svg?style=for-the-badge&logo=r&logoColor=white)
[![R-CMD-check](https://github.com/ArthurData/confetti/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/ArthurData/confetti/actions/workflows/R-CMD-check.yaml)
[![Codecov test coverage](https://codecov.io/gh/ArthurData/confetti/branch/main/graph/badge.svg)](https://app.codecov.io/gh/ArthurData/confetti?branch=main)
<!-- badges: end -->
The goal of `{confetti}` is to put some 🎊 confetti 🎊
in your Shiny Application.
This package uses a JavaScript library called: **[canvas-confetti](https://github.com/catdad/canvas-confetti)**.
#### Installation
You can install the development version of confetti from [GitHub](https://github.com/) with:
``` r
# install.packages("devtools")
devtools::install_github("ArthurData/confetti")
```
#### Example
Let's make a fun application with some confetti!
⚠ You will have to open your app in a new window with your favorite web browser to see confetti.
```{r example, eval=FALSE}
library(confetti)
library(shiny)
```
First, you have to use `useConfetti()` in the UI of your Shiny app. This function will attach all depencies for you.
```{r, eval=FALSE}
ui <- fluidRow(
useConfetti(),
actionButton(
inputId = "go",
label = "Default confetti"
),
actionButton(
inputId = "go2",
label = "Colored confetti"
)
)
```
Then, in you server, call the `sendConfetti()` or `sendfireworks()` function whatever you want.
Here, every time an `actionButton` is clicked, the according `observeEvent` is launch and send confetti.
A dedicated input called `sentConfetti` is added and counts the number of times confetti is sent.
```{r, eval=FALSE}
server <- function(input, output, session) {
observeEvent(input$go, {
sendConfetti()
message("You have sent ", input$sentConfetti, " confetti")
})
observeEvent(input$go2, {
sendConfetti(
colors = list("#DAB436", "#36DA62", "#365CDA", "#DA36AE")
)
message("You have sent ", input$sentConfetti, " confetti")
})
}
```
Full code:
<details>
```{r, eval=FALSE}
library(confetti)
library(shiny)
ui <- fluidRow(
useConfetti(),
actionButton(
inputId = "go",
label = "Default confetti"
),
actionButton(
inputId = "go2",
label = "Colored confetti"
)
)
server <- function(input, output, session) {
observeEvent(input$go, {
sendConfetti()
message("You have sent ", input$sentConfetti, " confetti")
})
observeEvent(input$go2, {
sendConfetti(
colors = list("#DAB436", "#36DA62", "#365CDA", "#DA36AE")
)
message("You have sent ", input$sentConfetti, " confetti")
})
}
shinyApp(ui = ui, server = server)
```
</details>
or run this example:
```{r, eval=FALSE}
runApp(system.file("shiny", "example", "app.R", package = "confetti"))
```
#### Code of Conduct
Please note that the confetti project is released with a [Contributor Code of Conduct](https://contributor-covenant.org/version/2/0/CODE_OF_CONDUCT.html). By contributing to this project, you agree to abide by its terms.