Hi,
The code still suffers from the same problem, meaning that it will execute the output$output1 <- renderTable
twice when you change input1 and you have a different input2 (plust the code starts with an error message, but that's besides the point).
So, if the app is running and input1 = file1 and input2 = bread, and you change input1 to file2, the code is run once. But, if input1 = file1 and input2 = oranges and you change input1 to file2, the code is run twice.
Again, the main question I have is just why explicitly updating a reactive variable to the same value is not triggering it.
Here is another reprex:
library(shiny)
ui <- fluidPage(
numericInput("input1", "Set a value", value = 0),
actionButton("click", "Click")
)
server <- function(input, output, session) {
myVal = reactiveVal()
observeEvent(input$click, {
print("click registered")
myVal(input$input1)
}, ignoreInit = T)
observeEvent(myVal(), {
showModal(modalDialog("Update"))
}, ignoreInit = T)
}
shinyApp(ui, server)
If you click the button once after you changed the value, there will be a pop-up. But if you click the button again, nothing will happen, although in the code the value gets updated explicitly (with the same value)
It's really a theoretical question. I know you can solve this by putting the modal in the first observeEvent that looks for the click, but the point is that I don't get it why the value wont trigger reactivity if it gets updated with the exact same value.
In my real example, there is a lot more going on and there is need to have two separate observeEvents so I can't merge them. If I do, I end up with the double execution again.
Don't worry, I did find a workaround with some additional variables, but I just would like to know why this isn't updating the way you'd expect.
PJ