-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit b0ad60e
Showing
22 changed files
with
1,069 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
Package: r2fireworks | ||
Type: Package | ||
Title: Enhance Your 'Rmarkdown' and 'shiny' Apps with Dazzling | ||
Fireworks Celebrations | ||
Version: 0.1.0 | ||
Authors@R: c( | ||
person("Obinna", "Obianom", email = "idonshayo@gmail.com", role = c("aut", "cre"))) | ||
Maintainer: Obinna Obianom <idonshayo@gmail.com> | ||
Description: Implementation of 'JQuery' <https://jquery.com> and 'CSS' styles to allow the display of fireworks on a document. Toolkit to easily incorporate celebratory splashes in 'Rmarkdown' and 'shiny' apps. | ||
License: MIT + file LICENSE | ||
URL: https://r2fireworks.obi.obianom.com/ | ||
BugReports: https://github.com/oobianom/r2fireworks/issues | ||
Depends: R (> 3.6) | ||
Imports: utils, htmltools, shiny | ||
Suggests: rmarkdown, knitr | ||
Encoding: UTF-8 | ||
VignetteBuilder: knitr | ||
Language: en-US | ||
LazyData: false | ||
RoxygenNote: 7.2.3 | ||
NeedsCompilation: no | ||
Packaged: 2024-01-16 14:27:34 UTC; in198 | ||
Author: Obinna Obianom [aut, cre] | ||
Repository: CRAN | ||
Date/Publication: 2024-01-16 17:50:02 UTC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
YEAR: 2024 | ||
COPYRIGHT HOLDER: Obinna Obianom |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
2ef624884d975f7f7eb5d47cf73f9d5d *DESCRIPTION | ||
e5c67079d1412c12740c985b7003df51 *LICENSE | ||
6da6d40ea4df9377eebc390bcfd7ef46 *NAMESPACE | ||
ebe8bb9be2e33c110579d5d02dc4a16a *NEWS.md | ||
15bbe22928d9675fccbbff4fb8a7b817 *R/aaa.R | ||
e3da903fb2ec5b37130675da14b50719 *R/actions.R | ||
92c6a38e5e6035a6717b9f960d17d103 *R/initialize.R | ||
da7bac5323d313dfbcdb38f8fbf613f0 *R/r2fireworks-package.R | ||
74b7b13cae406197c15845ea20e76cfc *README.md | ||
e66586fe220d9f29a97300b3f089af53 *build/vignette.rds | ||
9ee97da1f25d700f4d64c87d5d242c29 *inst/doc/introduction_r2fireworks.Rmd | ||
d49141629e2b7bacf781a784309f9bcd *inst/doc/introduction_r2fireworks.html | ||
71c4138d6439bd3a5a982f8aa6e37b4c *inst/examples/sample1.Rmd | ||
a76e5a124de771cbde3606a39b9b2f09 *inst/examples/server.R | ||
f0a7228857a2a17127e77d843db217bf *inst/examples/ui.R | ||
31d273e0fe5deb9845cef7cc3ea08610 *inst/themes/r2fireworks.css | ||
f532efa052f99ca377c2c1d46e547fd7 *inst/themes/r2fireworks.js | ||
9a2956ff79d96627b9112b5fcb9ad65f *man/fireworkMessenger.Rd | ||
740cb5da00680d0bcf24a8cc4cab97da *man/r2fireworks-package.Rd | ||
7c146aec89a92592e9a293a02b186594 *man/useFireworks.Rd | ||
9ee97da1f25d700f4d64c87d5d242c29 *vignettes/introduction_r2fireworks.Rmd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Generated by roxygen2: do not edit by hand | ||
|
||
export(addRmdFireworks) | ||
export(fireworkMessenger) | ||
export(removeFireworks) | ||
export(showFireworks) | ||
export(useFireworks) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# r2fireworks 0.1.0 | ||
|
||
- Basic fireworks for Rmarkdown and Shiny apps |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.onLoad <- function(lib, pkg) { | ||
} | ||
|
||
utils::globalVariables(c("getDefaultReactiveDomain")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#' Widget to initiate or terminate fireworks display | ||
#' | ||
#' Add or remove fireworks graphics from page | ||
#' | ||
#' @param type type of action e.g start, remove | ||
#' @param duration duration of fireworks outbursts | ||
#' @param speed speed of display of fireworks | ||
#' @param particleCount particle size of fireworks | ||
#' @param session session object from server | ||
#' @return inclusion or exclusion of fireworks from page | ||
#' @rdname fireworkMessenger | ||
#' @export | ||
|
||
fireworkMessenger <- function(type,duration=NULL,speed=NULL, particleCount = 30, session = getDefaultReactiveDomain()){ | ||
if(!is.null(duration)) warning("argument is still being developed. check next version") | ||
session$sendCustomMessage("fwstatus598", list( | ||
what = type, | ||
duration = duration, | ||
speed = speed, | ||
particleCount = particleCount | ||
)) | ||
} | ||
|
||
|
||
#' Display fireworks on page | ||
#' | ||
#' Add fireworks visuals to page | ||
#' @return visible firework canvas on the page | ||
#' @rdname fireworkMessenger | ||
#' @export | ||
|
||
showFireworks <- function( speed = 1, particleCount = 40, session = getDefaultReactiveDomain()){ | ||
fireworkMessenger(type = "start", speed = speed, particleCount = particleCount) | ||
} | ||
|
||
|
||
#' Remove fireworks on page | ||
#' | ||
#' Remove fireworks visuals from page | ||
#' | ||
#' @return removal of firework canvas from the page | ||
#' @rdname fireworkMessenger | ||
#' @export | ||
|
||
removeFireworks <- function(session = getDefaultReactiveDomain()){ | ||
fireworkMessenger(type = "remove") | ||
} | ||
|
||
|
||
#' Add fireworks on Rmarkdown page | ||
#' | ||
#' Add fireworks visuals to Rmarkdown page | ||
#' | ||
#' @return addition of firework canvas on the page | ||
#' @rdname fireworkMessenger | ||
#' | ||
#' @examples | ||
#' # In R markdown documents | ||
#' library(r2fireworks) | ||
#' useFireworks() | ||
#' addRmdFireworks(particleCount = 100, speed = 3) | ||
#' | ||
#' @export | ||
|
||
addRmdFireworks <- function(speed = 1, particleCount = 40){ | ||
stopifnot(speed > 0) | ||
return(htmltools::HTML( | ||
paste0("<script> | ||
var isRmd = true;var isRmdspeed = ",speed,";var isRmdpc = ",particleCount," | ||
</script>" | ||
))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
#' Set up firework scripts and loader | ||
#' | ||
#' Calls to load fireworks to a page | ||
#' | ||
#' | ||
#' @section Examples for r2fireworks: | ||
#' More examples and demo pages are located at this link - | ||
#' \url{https://r2fireworks.obi.obianom.com}. | ||
#' | ||
#' @return scripts to load fireworks and trigger to start fireworks | ||
#' | ||
#' @examples | ||
#' | ||
#' # In shiny applications | ||
#' | ||
#' if(interactive()){ | ||
#' # example 1: simple example with automatic start | ||
#' library(shiny) | ||
#' library(r2fireworks) | ||
#' | ||
#' ui <- fluidPage( | ||
#' useFireworks(), | ||
#' shiny::tags$h1("Introducing r2fireworks"), | ||
#' shiny::tags$p("Celebrate 4th of July and my R package!!!") | ||
#' ) | ||
#' server <- function(input, output, session) { | ||
#' # optional. start fireworks on load | ||
#' showFireworks(particleCount = 30) | ||
#' } | ||
#' | ||
#' shinyApp(ui, server) | ||
#' | ||
#' | ||
#' | ||
#' | ||
#' | ||
#' | ||
#' | ||
#' # example 2: sample with start and stop buttons | ||
#' library(shiny) | ||
#' library(r2fireworks) | ||
#' | ||
#' ui <- fluidPage( | ||
#' useFireworks(), | ||
#' shiny::tags$h1("Here is the starts"), | ||
#' shiny::tags$p("Celebrate 4th of July and my R package!!!"), | ||
#' actionButton("startFW","Show and Start Fireworks, with speed x1"), | ||
#' actionButton("startFWx4","Show and Start Fireworks, with speed x4"), | ||
#' actionButton("startFWspx4","Show Fireworks, with particle burst size 10000"), | ||
#' actionButton("stopFW","Remove Fireworks") | ||
#' ) | ||
#' | ||
#' server <- function(input, output, session) { | ||
#' observeEvent(input$startFW,{ | ||
#' showFireworks() | ||
#' }) | ||
#' | ||
#' observeEvent(input$startFWx4,{ | ||
#' showFireworks(speed = 4,particleCount = 50) | ||
#' }) | ||
#' | ||
#' observeEvent(input$startFWspx4,{ | ||
#' showFireworks(speed = 1,particleCount = 10000) | ||
#' }) | ||
#' observeEvent(input$stopFW,{ | ||
#' removeFireworks() | ||
#' }) | ||
#' } | ||
#' | ||
#' } | ||
|
||
#' | ||
#' @export | ||
|
||
useFireworks <- function(){ | ||
template.loc1 <- file.path(find.package(package = pkgn), "themes") | ||
css <- paste0(.packageName, ".css") | ||
js <- paste0(.packageName, ".js") | ||
|
||
if (interactive()) { | ||
# include scripts | ||
htmltools::htmlDependency( | ||
pkgn, vers, | ||
src = template.loc1, | ||
script = js, | ||
stylesheet = css, | ||
all_files = TRUE | ||
) | ||
|
||
} else { | ||
# fetch scripts | ||
fetch.css <- readLines(file.path(template.loc1, css)) | ||
fetch.js <- readLines(file.path(template.loc1, js)) | ||
|
||
# combine scripts | ||
combine.css.js <- c( | ||
"<", scr.elm[1], ">", fetch.css, "</", scr.elm[1], ">", | ||
"<", scr.elm[2], ">", fetch.js, "</", scr.elm[2], ">" | ||
) | ||
|
||
# collapse and set to html | ||
tear.combo <- paste(combine.css.js, collapse = "") | ||
# set to html | ||
attr(tear.combo, "html") <- TRUE | ||
class(tear.combo) <- c("html", "character") | ||
# display html | ||
return(tear.combo) | ||
} | ||
} | ||
|
||
scr.elm <- c("style", "script", "html") | ||
pkgn <- .packageName | ||
vers <- "1.1.0" | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#' @keywords internal | ||
"_PACKAGE" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
# r2fireworks: Add/remove celebratory fireworks to your Rmarkdown and Shiny application | ||
|
||
### Official site: https://r2fireworks.obi.obianom.com | ||
|
||
![](https://r2fireworks.obi.obianom.com/r2fireworks_out.gif) | ||
|
||
### Installation and Library Attachment | ||
|
||
The r2social package is available on CRAN and can be installed as shown below | ||
|
||
`remotes::install_github("oobianom/r2fireworks")` | ||
|
||
Attach library | ||
|
||
`library(r2social)` | ||
|
||
|
||
### Shiny application | ||
|
||
```{r} | ||
# simple example with automatic start | ||
library(shiny) | ||
library(r2fireworks) | ||
ui <- fluidPage( | ||
useFireworks(), | ||
shiny::tags$h1("Introducing r2fireworks"), | ||
shiny::tags$p("Celebrate 4th of July and my R package!!!") | ||
) | ||
server <- function(input, output, session) { | ||
# optional. start fireworks on load | ||
showFireworks(particleCount = 30) | ||
} | ||
shinyApp(ui, server) | ||
# example with start and stop buttons | ||
library(shiny) | ||
library(r2fireworks) | ||
ui <- fluidPage( | ||
useFireworks(), | ||
shiny::tags$h1("Here is the starts"), | ||
shiny::tags$p("Celebrate 4th of July and my R package!!!"), | ||
actionButton("startFW","Show and Start Fireworks, with speed x1"), | ||
actionButton("startFWx4","Show and Start Fireworks, with speed x4"), | ||
actionButton("startFWspx4","Show Fireworks, with particle burst size 10000"), | ||
actionButton("stopFW","Remove Fireworks") | ||
) | ||
server <- function(input, output, session) { | ||
observeEvent(input$startFW,{ | ||
showFireworks() | ||
}) | ||
observeEvent(input$startFWx4,{ | ||
showFireworks(speed = 4,particleCount = 50) | ||
}) | ||
observeEvent(input$startFWspx4,{ | ||
showFireworks(speed = 1,particleCount = 10000) | ||
}) | ||
observeEvent(input$stopFW,{ | ||
removeFireworks() | ||
}) | ||
} | ||
``` | ||
|
||
### Rmarkdown document | ||
|
||
``` | ||
--- | ||
title: "r2fireworks: add celebratory fireworks to page" | ||
output: | ||
html_document: | ||
theme: default | ||
--- | ||
#### Example | ||
``{r} | ||
library(r2fireworks) | ||
useFireworks() | ||
addRmdFireworks(particleCount = 30, speed = 3) | ||
`` | ||
``` | ||
|
||
``` |
Binary file not shown.
Oops, something went wrong.