Skip to content

Instantly share code, notes, and snippets.

@johndrummond
Created May 13, 2019 11:48
Show Gist options
  • Save johndrummond/f28d3784b6b9ec553f8c25f976a92d26 to your computer and use it in GitHub Desktop.
Save johndrummond/f28d3784b6b9ec553f8c25f976a92d26 to your computer and use it in GitHub Desktop.
code showing that an observer that sets a reactive value, isn't invalidated by the reactive value being set elsewhere
#
#
library(shiny)
# Define UI for application that draws a histogram
ui <- fluidPage(
# Application title
titlePanel("Reactive values updating"),
actionButton("button1","button1"),
verbatimTextOutput("button1")
)
# Define server logic required to draw a histogram
server <- function(input, output) {
testRV <- reactiveValues()
testRV$val1 <- 0
output$button1 <- renderText({
isolate({testRV$val1 <- testRV$val1 + 1})
result_txt <- paste("button pushed ",input$button1,"val1:", isolate(testRV$val1))
print(result_txt)
paste(result_txt )
})
observe({
print("observer set RV fired")
testRV$val1 <- 27
})
observe({
print(paste("observer using RV fired", testRV$val1))
})
}
# Run the application
shinyApp(ui = ui, server = server)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment