Rasmus
Rasmus

Reputation: 23

Using extendedTask in Shiny to render UI asynchronously

I have a Shiny app with many module outputs (say cards in a dashboard). Natively Shiny will not render updates until the end of the flush cycle, at which point all UI elements will be updated simultaneously. I don't want this, I want them to be updated as they are done.

I can achieve this using extendedTask. None of the outputs are slow enough to justify actually running them asynchronously (because of the overhead). Instead I can set up an extendedTask per ui elements that only returns TRUE. This works and the module outputs render as soon as they are done, but it's very hacky. It requires a separate R session running, transferring data and so on for no real reason.

Is there some other way to get around this and have outputs rendering immediately without waiting for the end of the flush cycle? I'm thinking it's likely to involve extendedTask somehow. Optimally I'd like to wrap the whole module call in extendedTask but that wouldn't work.

foo <- ExtendedTask$new(function() {
      future(
        {
          TRUE
        },
        seed = NULL
      )
    })
    
observeEvent(genes(), {
  foo$invoke()
})

output$some_plot <- renderPlot({
  req(foo$result())
  req(genes())
  # Some plot that only uses genes() and doesn't care at all about foo.
})

Upvotes: 0

Views: 25

Answers (0)

Related Questions