Created
August 2, 2023 20:26
-
-
Save MayaGans/154264a46ad56f08ad59635149637e19 to your computer and use it in GitHub Desktop.
reactiveValues are weird and dont copy on modify
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) | |
ui <- fluidPage( | |
actionButton("debug", "DEBUG") | |
) | |
server <- function(input, output, session) { | |
inputs <- reactiveValues(a = 1) | |
new_inputs <- inputs | |
observeEvent(input$debug, { | |
print("---- inputs ---") | |
print(lobstr::obj_addr(inputs)) | |
print("---- inputs$a ---") | |
print(lobstr::obj_addr(inputs$a)) | |
# MAKE A CHANGE TO THE COPY | |
new_inputs$a <- 2 | |
print(" ----- CHANGED COPY ----- ") | |
# THE ORIGINAL INPUT IS CHANGED!!! | |
print("---- inputs ---") | |
print(lobstr::obj_addr(inputs)) | |
print("---- inputs$a ---") | |
print(lobstr::obj_addr(inputs$a)) | |
print("---- new_inputs ---") | |
print(lobstr::obj_addr(new_inputs)) | |
print("---- new_inputs$a ---") | |
print(lobstr::obj_addr(new_inputs$a)) | |
}) | |
# but this isnt triggered?! | |
observeEvent(inputs, { | |
# browser() | |
}) | |
} | |
shinyApp(ui, server) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment