I want to write a version of tar_visnetwork() that refreshes at regular intervals while the pipeline is running. But every time I print a visNetwork widget, it creates its own graphics device. Simply printing every couple seconds would produce thousands of unwanted graphs.
Oops, I think I posted this question too soon. I was thinking out loud and did not connect the dots right away. I think I could avoid this problem if I just write a small Shiny app that repeatedly calls tar_visnetwork().
# Install targets
# remotes::install_github("wlandau/targets")
# Define an example _targets.R file with a slow pipeline.
library(targets)
tar_script({
sleep_run <- function(...) {
Sys.sleep(10)
}
tar_pipeline(
tar_target(settings, sleep_run()),
tar_target(data1, sleep_run(settings)),
tar_target(data2, sleep_run(settings)),
tar_target(data3, sleep_run(settings)),
tar_target(model1, sleep_run(data1)),
tar_target(model2, sleep_run(data2)),
tar_target(model3, sleep_run(data3)),
tar_target(figure1, sleep_run(model1)),
tar_target(figure2, sleep_run(model2)),
tar_target(figure3, sleep_run(model3)),
tar_target(conclusions, sleep_run(c(figure1, figure2, figure3)))
)
})
# Run the pipeline in a separate R process.
px <- tar_make(callr_function = callr::r_bg)
# Run the app in the main process. Watch it refresh every 10 seconds.
# New targets should appear built each time.
tar_watch(seconds = 10, outdated = FALSE, targets_only = TRUE)