Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plots are not displayed in realtime in a loop #83

Closed
jinlow opened this issue Oct 13, 2021 · 3 comments · Fixed by #102
Closed

Plots are not displayed in realtime in a loop #83

jinlow opened this issue Oct 13, 2021 · 3 comments · Fixed by #102
Labels
bug Something isn't working enhancement New feature or request help wanted Extra attention is needed

Comments

@jinlow
Copy link

jinlow commented Oct 13, 2021

Describe the bug

I have a package that has some interactivity, that depends on being able to display plots in a loop. In RStudio, all plots display, but in an httpgd session they are not, only the first plot, and then all of them after the interactivity ends.

To Reproduce

The following R code run in a vanilla R session, only the first plot is displayed, subsequent plots are not displayed until "q" is pressed.

httpgd::hgd()
httpgd::hgd_browse()

data(mtcars)
while (TRUE) {
  cat("Enter 'p' to print a plot, and 'q' to quit.")
  command <- readLines(n=1)
  if (command == "p") {
    var = sample(colnames(mtcars), 1)
    barplot(table(mtcars[[var]]), main = var)
  }
  if (command == "q") {
    break
  }
}

Expected behavior

I would expect all of the plots to display interactively, every time "p" is entered a new plot would be displayed.

Screenshots

Here I have pressed "p" several times and only one plot is printed.
image

Only after pressing "q" and the loop ending, are all the plots displayed.
image

Environment

  • OS: Windows
  • Browser: Chrome
  • R version: 4.1.1
  • httpgd version: 1.2.1
@jinlow jinlow added the bug Something isn't working label Oct 13, 2021
@nx10
Copy link
Owner

nx10 commented Oct 14, 2021

Thank you for this bug report and for the reproducible example code.
I think this is caused by httpgd waiting for the R session to finish executing, but it is not intended behavior.
I will see what I can do.

@renkun-ken
Copy link
Contributor

Original issue: REditorSupport/vscode-R#813.

@nx10 nx10 mentioned this issue Oct 25, 2021
4 tasks
@nx10
Copy link
Owner

nx10 commented Dec 4, 2021

This is caused by later preventing calling R when there is something on the call stack r-lib/later#159

We have to wait if the later devs consider adding functionality to disable this check. Otherwise we would have to implement a complete later replacement for httpgd at some point. As this is platform dependent low level C code I want to avoid this when possible.

@nx10 nx10 added enhancement New feature or request help wanted Extra attention is needed labels Dec 4, 2021
@nx10 nx10 closed this as completed in #102 Feb 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants