MyNixOS website logo
Description

An Event-Based Mechanism for 'Shiny'.

An event-Based framework for building 'Shiny' apps. Instead of relying on standard 'Shiny' reactive objects, this package allow to relying on a lighter set of triggers, so that reactive contexts can be invalidated with more control.

gargoyle

R-CMD-check Lifecycle:stable

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

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

What the heck?

{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( "plop", "pouet", "poum")
  
  # 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.

Metadata

Version

0.0.1

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows