GithubHelp home page GithubHelp logo

confetti's Introduction

{confetti}

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() 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.

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.

confetti's People

Contributors

arthurdata avatar

Stargazers

 avatar

Watchers

 avatar

confetti's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.