How to Retrieve the Last Reactable Object

51 Views Asked by At

I am currently working with reactable in R and I am trying to find a way to retrieve the last reactable object, similar to how ggplot2::last_plot() is used to get the last plot object. How can I achieve this?

library(reactable)
reactable(iris)

Now I want to retrieve the last reactable object. Something like last_reactable() (doesn't exist).

2

There are 2 best solutions below

0
I_O On BEST ANSWER

This should work on a session base:

  • hook a tracer to the desired function (here: reactable) so that the quoted code of the tracer argument executes on each call to reactable:
trace(what = reactable, tracer = quote(assign('.last_reactable_args',
                                         as.list(match.call()[-1]),
                                         envir = .GlobalEnv
                                  )))

Above code grabs the arguments reactable was called with and stores it as a hidden list in the global environment.

  • write a function last_table which calls reactable with this list (= the latest arguments):
last_reactable <- \() do.call(reactable, .last_reactable_args)

last_reactable now replays the latest reactable call.

0
山の平和 On

Just assign it to a variable and use it.

last_reactable <- reactable(iris)
last_reactable

If the variable is empty maybe there's not variable called that way.