nx10 / httpgd

Asynchronous http server graphics device for R.
https://nx10.github.io/httpgd
GNU General Public License v2.0
379 stars 19 forks source link

Plot not updated under remote development #11

Closed renkun-ken closed 4 years ago

renkun-ken commented 4 years ago

I'm on the latest commit (3c8507d) and find that the plot is not updated on adding elements under Remote Development environment.

For example,

httpgd::httpgd(port = 13588)
utils::browseURL(httpgd::httpgdURL())

plot(rnorm(100), main = "title")
abline(h = 0, col = "red")
points(rnorm(100), col = "blue")

Running plot() works well. But subsequent abline() and points() mostly do not update the plot as I run the code line by line. Resizing the page does not make the plot correct either. However, if I select the three lines and run them together, the plot is correct.

I tested with older version (7e3d8c3f58efc22be4b2c6710c062e54a828065c) and there's no such problem.

Kapture 2020-05-31 at 13 11 01

nx10 commented 4 years ago

I completely rewrote the R communication part today. Adding to the latest plot should work now, regardless of how many clients are running at the same time. In addition to that: Pages in the history that were previously rendered in the same resolution are recorded and don't need redraws from R any more. This makes history navigation pretty fast now.

It was a big code change. If you see any bug I introduced please let me know.

renkun-ken commented 4 years ago

Thanks for the nice work! With the latest commit, this problem is gone. But sometimes the following warning appears:

> plot(rnorm(100), main = "title")                                                                       
Warning messages:
1: display list redraw incomplete 
2: display list redraw incomplete 
3: display list redraw incomplete 

but I cannot reproduce it yet.

renkun-ken commented 4 years ago

I test the latest commit under remote development and the problem no longer occurs. Closing for now.

nx10 commented 4 years ago

This was still an issue even if it was only happening very rarely. I was able to reproduce it reliably with:

for (i in 1:1000) {hist(rnorm(100))}

or more isolated:

hist(rnorm(10),main="Plot 1");Sys.sleep(2);hist(rnorm(10),main="Plot 2")

This was very hard to solve. I have reworked the entire async backend (pretty big commit 07ef705e8a240e59812af9ed7fe53862efbbb63e) to both solve this and enable interacting with the server from the R session.