GitXplorerGitXplorer
C

gargoyle

public
56 stars
7 forks
5 issues

Commits

List of commits on branch master.
Verified
34ab8895333bf071b7d6dadd3f1aa0d28e3368c6

Merge pull request #20 from ilyaZar/fix-19

CColinFay committed 5 months ago
Verified
ed259b026ecaaebfb2d2882c7058657756b7d9cc

Merge pull request #18 from ilyaZar/fix-17

CColinFay committed 5 months ago
Verified
d15eaf13398cbb741e2f66f1f30bce52b9c005a0

Merge pull request #15 from ilyaZar/improve-docs

CColinFay committed 8 months ago
Unverified
d3d4de0002c2638ac1efb76b5a0bc1410ee78ce1

tests: improve tests to make coverage 100%

iilyaZar committed 2 years ago
Unverified
a85df9e34d8bdf2c76305bfbdf6da1767d579cdc

fix: pass argument session down to watch()

iilyaZar committed 2 years ago
Unverified
77150eac52504d0385c964742e69e449a29f558f

Be encouraging and precise

iilyaZar committed 2 years ago

README

The README file for this repository.

gargoyle

Lifecycle: stable R-CMD-check

The goal of gargoyle is to provide an event-based mechanism for {shiny}.

Installation

You can install the dev version of {gargoyle} with:

remotes::install_github("ColinFay/gargoyle")

About

You’re reading the doc about version : 0.0.1

This README has been compiled on the

Sys.time()
#> [1] "2023-03-27 16:53:20 CEST"

Here are the test & coverage results :

devtools::check(quiet = TRUE)
#> ℹ Loading gargoyle
#> ── R CMD check results ───────────────────────────────────── gargoyle 0.0.1 ────
#> Duration: 10.3s
#> 
#> 0 errors ✔ | 0 warnings ✔ | 0 notes ✔
covr::package_coverage()
#> gargoyle Coverage: 56.36%
#> R/funs.R: 51.02%
#> R/logs.R: 100.00%

What the heck?

{gargoyle} is a package that provides wrappers around {shiny} to turn your app into and event-based application instead of a full reactive app. The framework is centered around a listen & trigger mechanism.

It works with classical UI, and just needs tweaking the server side of your app.

{shiny}’s default reactive behavior is very helpful when it comes to building small applications. Because, you know, the good thing about reactivity is that when something moves somewhere, it’s updated everywhere. But the bad thing about reactivity is that when something moves somewhere, it’s updated everywhere. So it does work pretty well on small apps, but can get very complicated on bigger apps, and can quickly get out of hands.

That’s where {gargoyle} comes into play: it provides an event based paradigm for building your apps, so that things happen under a control flow.

For whom?

If you’re just building small {shiny} apps, you’re probably good with {shiny} default reactive behavior. But if ever you’ve struggled with reactivity on more bigger apps, you might find {gargoyle} useful.

The trade-off

{gargoyle} will be more verbose and will demand more work upfront to make things happen. I believe this is for the best if you’re working on a big project.

Design pattern

{gargoyle} has:

  • init, listen & trigger, which allow to initiate, listen on, and trigger an event

  • on, that runs the expr when the event in triggered

gargoyle::trigger() can print messages to the console using options("gargoyle.talkative" = TRUE).

Example

library(shiny)
library(gargoyle)
options("gargoyle.talkative" = TRUE)
ui <- function(request){
  tagList(
    h4('Go'),
    actionButton("y", "y"),
    h4('Output of z$v'),
    tableOutput("evt")
  )
}

server <- function(input, output, session){

  # Initiating the flags
  init("airquality", "iris", "renderiris")

  # Creating a new env to store values, instead of
  # a reactive structure
  z <- new.env()

  observeEvent( input$y , {
    z$v <- mtcars
    # Triggering the flag
    trigger("airquality")
  })

  on("airquality", {
    # Triggering the flag
    z$v <- airquality
    trigger("iris")
  })

  on("iris", {
    # Triggering the flag
    z$v <- iris
    trigger("renderiris")
  })

  output$evt <- renderTable({
    # This part will only render when the renderiris
    # flag is triggered
    watch("renderiris")
    head(z$v)
  })

}

shinyApp(ui, server)

You can then get & clear the logs of the times the triggers were called:

get_gargoyle_logs()
clear_gargoyle_logs()

Code of Conduct

Please note that the gargoyle project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.