webr icon indicating copy to clipboard operation
webr copied to clipboard

Any way to replot last or selected plot

Open Dual-Ice opened this issue 8 months ago • 0 comments

I need to implement functionality to replot (like in RStudio for ecample) last or selected plot instead of scale it. Any ideas how to do it ? I try this

.plot_history <- list()
.log_plot <- function(expr, value, succeeded, visible) {
  if (dev.cur() > 1) {
    dev.control("enable")
    
    .plot_history[[length(.plot_history) + 1]] <<- recordPlot()
  }
  return(TRUE)
}

addTaskCallback(.log_plot, name = "plot_logger")

plot(rnorm(100), main = "Random dots")
last_plot <- .plot_history[[length(.plot_history)]]

replayPlot(last_plot)

But nothing returns. Any ideas ?

Dual-Ice avatar Feb 13 '25 15:02 Dual-Ice