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

Plotting in an interactive loop does not render all plots. #813

Closed
jinlow opened this issue Oct 8, 2021 · 5 comments
Closed

Plotting in an interactive loop does not render all plots. #813

jinlow opened this issue Oct 8, 2021 · 5 comments
Labels

Comments

@jinlow
Copy link

jinlow commented Oct 8, 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 the vscode extension (both the base plotter, and the httpgd backend), only the first (and the last plot when you quit the loop) display.

To Reproduce
Create an R session, the following code reproduces this, but only the first plot displays interactivly.

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
  }
}

Do you want to fix by self? (We hope your help!)

I do not think I have the knowledge of VScode plugins to fix this myself.

Expected behavior
I would expect all of the plots to display interactively.

Screenshots
If applicable, add screenshots to help explain your problem.
You can show the keybord contents by pressing F1 and Developer: toggle screencast mode

Environment (please complete the following information):

  • OS: [e.g. Windows]
  • VSCode Version: [e.g. 1.60.2]
  • R Version: [e.g. 4.1.1]
  • vscode-R version: [e.g. 2.3.1]
@jinlow jinlow added the bug label Oct 8, 2021
@renkun-ken
Copy link
Member

I could reproduce this. It is not related to vscode-R but how httpgd triggers plot update via interactive user input.

In a vanilla R outside vscode, run R and create an httpgd device:

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

Then a web plot viewer is open in the browser. Run your code, and you will find that the same problem persists.

@renkun-ken
Copy link
Member

Please file an issue at https://github.com/nx10/httpgd/issues.

@jinlow
Copy link
Author

jinlow commented Oct 13, 2021

But this issue is present with the vscode-R extension, even when I am not using httpgd.

@renkun-ken
Copy link
Member

But this issue is present with the vscode-R extension, even when I am not using httpgd.

vscode-R by default uses a png device replayed in the task callback on top-level user input. It is a known limitation documented at https://github.com/REditorSupport/vscode-R/wiki/Plot-viewer#png-file. Using httpgd is always recommended.

@jinlow
Copy link
Author

jinlow commented Oct 13, 2021

Thanks @renkun-ken! That makes sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants