ArthurData / confetti

Put some confetti in your Shiny App πŸŽ‰

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

{confetti}

Lifecycle: experimental R-CMD-check Codecov test coverage

The goal of {confetti} is to put some 🎊 confetti 🎊 in your Shiny Application.

This package uses a JavaScript library called: canvas-confetti.

Installation

You can install the development version of confetti from GitHub with:

# 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.

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.

ui <- fluidRow(
  useConfetti(),
  actionButton(
    inputId = "go",
    label =  "Default confetti"
  ),
  actionButton(
    inputId = "go2",
    label = "Colored confetti"
  )
)

Then, in you server, call the sendConfetti() 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.

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:

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)

or run this example:

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. By contributing to this project, you agree to abide by its terms.

About

Put some confetti in your Shiny App πŸŽ‰

License:Other


Languages

Language:R 87.1%Language:JavaScript 12.9%