I have had in the last few days a very strange issue: I am observing that the same shiny app loads properly when I run my code line-by-line in RStudio, but it does not load when run as part of a larger code chunk run as one. In both cases this seems to be related to "leaky" abnormal behaviour from curly braces.
I have observed two similar instances with different apps/scripts:
Case 1: a simple app runs when code is executed line-by-line or as a whole by selecting the whole script directly, but not when the script is executed using the source() function. Inserting a time delay with Sys.sleep(10) did not help. Incidentally, in this case I also observe some "leakage" occurring, i.e. if a master script sequentially sources several smaller scripts (which I call "chunks" and are sequentially overwritten to the same local temp_chunk.R file), then I see chunk N+1 start executing when chunk N is still waiting for a Shiny app to load/complete. I wonder if the loop going through chunks could be progressing to the next step and sourcing the overwritten temp file, without waiting for the previous to complete, thus somehow corrupting the app created by the source() from the previous step?
Case 2: an if statement, if TRUE, will execute a very complex Shiny app then a simpler one. Code within the curly braces can be successfully run line-by-line, but when executing the whole code the second app does not load. I was able to solve that one by breaking the if statement into two separate curly braces controlled by the same repeated if check. After I did this, the code works even if I select the whole code and hit Ctrl+Enter.
In both cases, I get the following error in Firefox: Unable to connect
Firefox can’t establish a connection to the server at 127.0.0.1:5044.
The site could be temporarily unavailable or too busy. Try again in a few moments.
If you are unable to load any pages, check your computer’s network connection.
If your computer or network is protected by a firewall or proxy, make sure that Firefox is permitted to access the web.
If I run the app in a popup in RStudio instead, the popup remains gray forever.
Unfortunately, my code is massive and the issue is not easily reproducible, so I do not think that I am able to create a reproducible example easily. I can try to make it work if necessary, but for now I would appreciate a discussion on what might be cause.