rundel / livecode

GNU General Public License v3.0
118 stars 10 forks source link

R session hangs when executing code on an Rmarkdown file served by `livecode` #6

Open bitsandbricks opened 4 years ago

bitsandbricks commented 4 years ago

I've been testing livecode (which is awesome, by the way) as a tool to share the with my students as I write it. I teach using Rmarkdown, and quickly noticed that my R session sooner or later "hangs" when I execute a code chunk on and .Rmd file thats being served by livecod.

I've been able to reproduce the error running this (interactively, non knitting) as an .Rmd document:

server <- livecode:::serve_file()

At some point the session will become "unresponsive". That is, after trying to execute a code chunk it will show a stopwatch icon, and never finish. No other R instructions can be run after that.

Sometimes it fails immediately, just trying this:

print("Some R code")

If it works, then try this:

library(ggplot2)

Sometimes it survives up to this point. Just run the the following chunk over and over again and eventually it will fail:

print("Some R code, again")
rundel commented 4 years ago

I hadn't seen this specific behavior before but I've done most of my testing using R scripts instead of Rmds. I was able to recreate the issue and I think it is related to something I've seen previously when just running code in the console.

Occasionally while the server is running I will get a hang in the console when attempting to run something where it seems like R is hanging, input shows in the console but there is no output and the command prompt doesn't come back. What I have found is just hitting enter in the console at this point does bring everything back and then things proceed as expected.

The same thing seems to be happening with the Rmd where the document is hanging while it waits for the console to respond. Hitting enter on the console did fix this specific issue for me. Can you try and see if the same thing works for you?

This is definitely a deeper issue and I will need to play around to see if I can locate what is causing the hang - livecode, later, rstudio, etc.

bitsandbricks commented 4 years ago

The "press Enter on the console" trick works for me too! I can live with that :)

bastianolea commented 3 years ago

The same thing seems to be happening with the Rmd where the document is hanging while it waits for the console to respond. Hitting enter on the console did fix this specific issue for me. Can you try and see if the same thing works for you?

I haven’t been able to use livecode because of this issue. I start the livecode connection on a plain R document, the webpage opens, but my console is hijacked by livecode. The console doesn’t respond, only showing input, until several seconds have passed, almost at random. And when it finally shows output, it then hangs again. Pressing enter only makes a blank line in the input, without helping.

I’m using RStudio Server 1.3.1093 and R 3.6.3.

rundel commented 3 years ago

Thanks for the feedback, I haven't had a chance to look at this package in awhile so I haven't tested things with the newer versions of RStudio and R. I suspect that the underlying issue is an interaction between these and websocket, but I wasn't able to come up with a simple enough reprex.

I'm hoping to have some time in the near future to take a look at all of this again.