Skip to content

Instantly share code, notes, and snippets.

@hypebright
Created December 11, 2022 16:04
Show Gist options
  • Save hypebright/726617548046c9e5e04ef138c40a499b to your computer and use it in GitHub Desktop.
Save hypebright/726617548046c9e5e04ef138c40a499b to your computer and use it in GitHub Desktop.
gargoyle example using init, trigger and watch
library(shiny)
library(gargoyle)
ui <- function(){
tagList(
actionButton("go", "Show me"),
h4('Output of pass_around$data'),
tableOutput("table")
)
}
server <- function(input, output, session){
# Initiating the flags
init("airquality", "iris", "renderiris")
# Creating a new env to store values, instead of
# a reactive structure
pass_around <- new.env()
observeEvent(input$go , {
pass_around$data <- mtcars
# Triggering the flag
trigger("airquality")
})
on("airquality", {
# Triggering the flag
pass_around$data <- airquality
trigger("iris")
})
on("iris", {
# Triggering the flag
pass_around$data <- iris
trigger("renderiris")
})
output$table <- renderTable({
# This part will only render when the renderiris
# flag is triggered
watch("renderiris")
head(pass_around$data)
})
}
shinyApp(ui, server)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment