Skip to content

Using more than one 'name' argument for on()? #3

@shahreyar-abeer

Description

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

server <- function(input, output, session){
  
  # Initiating the flags
  init( "airquality", "iris", "renderiris", "a2")
  
  # 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")
  })
  
  observeEvent( input$y , {
    #z$v <- mtcars
    # Triggering the flag
    trigger("a2")
  })
  
  on("airquality", {
    # Triggering the flag
    z$v <- airquality
    trigger("iris")
  })
  
  on("iris", {
    # Triggering the flag
    z$v <- iris
    trigger("renderiris")
  })
  
  ## need to use both 'iris' & 'a2'
  on({"iris", "a2"},{
    print("observed!")
  })
  
  output$evt <- renderTable({
    # This part will only render when the renderiris
    # flag is triggered
    watch("renderiris")
    head(z$v) 
  })
  
}

shinyApp(ui, server)

Note: It doesn't work!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions