Created
December 11, 2022 16:04
-
-
Save hypebright/726617548046c9e5e04ef138c40a499b to your computer and use it in GitHub Desktop.
gargoyle example using init, trigger and watch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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