Shiny: Add outputOptions() to allow an output to render ASAP rather than wait for flush

Created on 11 May 2017  路  4Comments  路  Source: rstudio/shiny

Consider this code

library(shiny)

ui <- fluidPage(
  actionButton("btn", "Click"),
  uiOutput("out")
)

server <- function(input, output) {
  values <- reactiveValues(foo = NULL)

  observeEvent(input$btn, {
    values$foo <- "bar"
     Sys.sleep(1)
  })

  output$out <- renderUI({
    values$foo
  })
}

shinyApp(ui = ui, server = server)

It'd be useful to be able to tell shiny to update the text output immediately when the reactive value is assigned instead of waiting for the flush.

Consult Team Advanced High Low Type

Most helpful comment

I read this somewhere in the async package docs:

No inputs are received from the browser until all pending async outputs/observers have completed.

It reminded me of this issue. This means that async will not be useful to someone who's performing an expensive calculation and wants to continue to be able to use the app. I think the ability of being able to tell shiny to let an output render whenever it's ready without blocking the others, coupled with the new async capability, is going to be very powerful.

All 4 comments

(Thanks!)

I'd really like to see this feature added too.

If it's just text field I find this works (I have it wrapped inside an observeEvent):

withCallingHandlers({
  shinyjs::html("txt_field", "")
  message('foo')
},
message = function(m) { shinyjs::html(id = "txt_field", html = m$message, add = TRUE) }
)

I read this somewhere in the async package docs:

No inputs are received from the browser until all pending async outputs/observers have completed.

It reminded me of this issue. This means that async will not be useful to someone who's performing an expensive calculation and wants to continue to be able to use the app. I think the ability of being able to tell shiny to let an output render whenever it's ready without blocking the others, coupled with the new async capability, is going to be very powerful.

No inputs are received from the browser until all pending async outputs/observers have completed.

Just for the record: regarding async there is a non-blocking workaround.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Stophface picture Stophface  路  3Comments

hlherrera picture hlherrera  路  5Comments

howardcoleman picture howardcoleman  路  5Comments

dmpe picture dmpe  路  4Comments

mdec picture mdec  路  5Comments