How to grab focus of RStudioGD prior to a looping plot

I have code which plots real-time information. This is just set up as an infinite while loop that fetches the information, plots it, then sleeps a set time.

Whilst this updates happily in the graphical device, the focus does not shift to it initially (at least in RStudio 1.4.1717 under Linux).

I have tried, grid::grid.newpage() before the loop code, but they do not shift the focus either as they would if run on their own. I suspect it is because the looping function never returns.

My question is, is there a way to do this? I can use of course, but I prefer the plot to appear in the default device. However in RStudio, if the initial focus is say on the Files pane or the Help pane, the plot could be happily updating in the Plot pane, but it would be hidden and the user would need to manually switch to it.

Reproducible example below:

looping <- function() {
  i <- 1
  while(TRUE) {
    if(i %% 2 == 0) print(ggplot2::qplot(iris$Sepal.Width))
    else print(ggplot2::qplot(iris$Sepal.Length))
    i <- i + 1

Created on 2021-07-09 by the reprex package (v2.0.0)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.