yihui / servr

A simple HTTP server in R
https://cran.rstudio.com/package=servr
278 stars 35 forks source link

inf_mr() opening new instances when saving .Rmd file in R Studio #59

Closed lsundnli closed 1 year ago

lsundnli commented 2 years ago

Thanks for this cool tool! Used it successfully at a group meeting yesterday. It's a bit quirky, but I can see myself saving time in the future. Here's a small bug report for an otherwise useful too. I hope it becomes more developed over time.

System: Mac M1 OSX 12.4 (Monterey) R-Studio 2022.07.0 Build 548 Xaringan Versino: 0.25.2

When launching inf_mr() to visualize live editing of a .Rmd file for presentations inside of R-studio, the first instance runs in the viewer of R-studio. The second instance opens in a browser windows (e.g. Chrome) which is a good for 2nd monitor presentations. When saving the .Rmd file after making changes because inf_mr() doesn't update r code blocks for live editing/visualization, the browser opens up ANOTHER tab to the exact same address:port (e.g. ... http://127.0.0.1:4321/YourXaringanPresntation.html?viewer_pane=1&capabilities=1&host=http%#A%#A%#A%#A%#A etc... )

This causes strange syncing issues between multiple tabs when trying to run the slide presentation (i.e. next slide forces back one slide from another tab - i.e. slides presentation becomes 'sticky') from one of the browser tabs or R-studio viewer, but is solved by closing all but one tab and time.

yihui commented 2 years ago

I can't reproduce this issue on my macOS and don't have an idea how it could happen (sounds like an RStudio IDE issue). I guess it won't help, but could you try to upgrade RStudio?

You can also try to clear the RStudio Viewer (using the broom button) when the slides are being previewed in your browser. See if that prevents new tabs.

lsundnli commented 2 years ago

I did try to upgrade RStudio, and it didn't help. It's not entirely consistent, happens about 1/2 the time now. Only when there are two servrs one serving the viewer and one chrome. All it does is open a new browser window, so a bit annoying but not critical.

yihui commented 2 years ago

I think this is the same issue as I reported to the RStudio IDE a few years ago: https://github.com/rstudio/rstudio/issues/3577#issuecomment-633722777

Basically you should only run inf_mr() only once. If you run it multiple times, RStudio can open new tabs in your browser after the slides are rebuilt and refreshed.