Refresh an existing HTML widget

Is there a way to refresh an existing widget without printing an additional copy of the widget in my web browser or the RStudio IDE viewer pane?

The tar_visnetwork() function in targets produces a visNetwork widget with colors to show the status of each target (examples here).

Screen Shot 2020-12-16 at 8.26.57 PM

With tar_visnetwork(outdated = FALSE), you can show more specific runtime progress information.

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().

Well, as silly as I feel for having asked this question, it has a really cool outcome. In A Shiny app and module to monitor runtime progress. by wlandau · Pull Request #248 · ropensci/targets · GitHub, I built an app and module to monitor the progress of a targets pipeline. It refreshes tar_visnetwork() every few seconds to update the user on what the pipeline is doing. Example:

# Install targets
# remotes::install_github("wlandau/targets")

# Define an example _targets.R file with a slow pipeline.
  sleep_run <- function(...) {
    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)

This topic was automatically closed 7 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.