Package 'gargoyle'

Title: An Event-Based Mechanism for 'Shiny'
Description: 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.
Authors: Colin Fay [aut, cre]
Maintainer: Colin Fay <[email protected]>
License: MIT + file LICENSE
Version: 0.0.1
Built: 2024-06-30 06:57:27 UTC
Source: https://github.com/colinfay/gargoyle

Help Index


Handle logs

Description

Get / Clear the logs of all the time the 'trigger()' functions are launched.

Usage

get_gargoyle_logs()

clear_gargoyle_logs()

Value

A data.frame of the logs.

Examples

if (interactive()){
  get_gargoyle_logs()
  clear_gargoyle_logs()
}

Initiate, trigger, event

Description

Initiate, trigger, event

Usage

init(..., session = getDefaultReactiveDomain())

trigger(..., session = getDefaultReactiveDomain())

watch(name, session = getDefaultReactiveDomain())

Arguments

session

The shiny session object

name, ...

The name(s) of the events

Value

The 'session' object invisibly. These functions are mainly used for side-effects.

Examples

if (interactive()){
  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)

}

React on an event

Description

React on an event

Usage

on(name, expr, session = getDefaultReactiveDomain())

Arguments

name

the name of the event to react to

expr

the expression to run when the event is triggered.

session

The shiny session object

Value

An observeEvent object. This object will rarely be used, 'on' is mainly called for side-effects.