ashokkrish / episim

episim is an R Shiny app for mathematical modelling of infectious diseases
GNU General Public License v3.0
4 stars 3 forks source link

Reactive value propagation causes the reactive value *population*, or others, to be missing for short periods of time #98

Open ashokkrish opened 5 months ago

ashokkrish commented 5 months ago

Another error when I directly run the app and load an SEIR model

Warning: Error in <Anonymous>: argument "population" is missing, with no default
  119: <Anonymous> [C:\Users\ashok\Desktop\spatialEpisim2022\episim\R\exposuRe.R#21]
  114: <reactive:renderModel> [C:\Users\ashok\Desktop\spatialEpisim2022\episim/server.R#93]
   98: renderModel
   97: renderUI [C:\Users\ashok\Desktop\spatialEpisim2022\episim/server.R#149]
   96: func
   83: renderFunc
   82: output$outputPanel
    1: runApp
bryce-carson commented 5 months ago

Another error when I directly run the app and load an SEIR model

Warning: Error in <Anonymous>: argument "population" is missing, with no default
  119: <Anonymous> [C:\Users\ashok\Desktop\spatialEpisim2022\episim\R\exposuRe.R#21]
  114: <reactive:renderModel> [C:\Users\ashok\Desktop\spatialEpisim2022\episim/server.R#93]
   98: renderModel
   97: renderUI [C:\Users\ashok\Desktop\spatialEpisim2022\episim/server.R#149]
   96: func
   83: renderFunc
   82: output$outputPanel
    1: runApp

This is a timing issue in the reactive graph. I have adopted "debouncing" which helps with this, but can't be hoped to always remove the error. Sometimes an error will appear briefly but then the reactive value will become available and the simulation will then run.

I can investigate work on this issue if you'd like, @ashokkrish, but the solution is essentially: add all the relevent inputs as needed values in the reactive. It's not elegant, but it would work and prevent this stage from happening and always result in an innocuous client-side message describing that the user should simply be patient for 1/4 second for a value to propagate through the server.

Timing can be a big issue with reactivity, but only for novice developers (like myself). The reactivity and time intersection is a difficult one to navigate.

ashokkrish commented 5 months ago

@Toby-exe @kle6951 I have reopened this issue and assigned it to Tobi and Khanh. Please make sure this is fully addressed and the error no longer appears.

This is happening more often than a user would want to see. I feel we need to clear the variables and results in memory fully when the user changes to a different model from the dropdown.

bryce-carson commented 5 months ago

This is happening more often than a user would want to see. I feel we need to clear the variables and results in memory fully when the user changes to a different model from the dropdown.

That is not a viable solution. I'm not sure how you're understanding the problem, but from the engineering side of things the problem is the variable has not yet been assigned a value when the variable is first read.

The variables are read eagerly, before a value is assigned to them. That's why the error occurs. It's an ephemeral error, however; a value is eventually written to the variable and then the model is re-run with the value available, so it is an "automatic, self-fixing issue."

It will take some expertise to resolve entirely and prevent the eager reading. I will need to work with everyone to get all of us on the same page in understanding so the responsibility for maintenance can change hands.