You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here's an app that demonstrates the issue. If the observer's expression returns a promise, then Shiny blocks until that promise is resolved. If, on the other hand, it returns something else, then that promise will still run, but Shiny won't block waiting for it. This is something that both I and @aronatkins have run into, and it would be helpful if it were better documented in https://rstudio.github.io/promises/articles/shiny.html.
library(shiny)
library(future)
library(promises)
plan("multisession")
server<-function(input, output) {
messages<- reactiveVal()
observeEvent(input$go, {
messages('starting sleep in other session...')
p<- future({
Sys.sleep(3)
})
p<- then(p, function(value) {
messages(c(messages(), 'completed sleep'))
})
if (input$return_value=="NULL") {
ret<-NULL
} elseif (input$return_value=="promise") {
ret<-p
}
ret
})
output$messages<- renderText(
paste0(messages(), collapse="\n")
)
}
ui<- fluidPage(
p(
"Returning NULL causes the message to update two times: one time immediately, and one time after ",
"the future (and subsequent promise) is resolved. "
),
p(
"Returning a promise causes the message to update only once: Shiny blocks ",
"until the future (and subsequent promise) is resolved."
),
radioButtons("return_value", "Return value for observer", c("NULL", "promise")),
actionButton("go", "Go"),
tags$pre(tags$code(textOutput("messages")))
)
shinyApp(ui=ui, server=server)
The text was updated successfully, but these errors were encountered:
For anyone who comes across this issue: There are (unsafe) ways of getting around this, such as returning NULL as the last statement in an observer. But, it would be great to have a safe means of doing this. You can indicate your support for such a request by upvoting this issue comment.
Here's an app that demonstrates the issue. If the observer's expression returns a promise, then Shiny blocks until that promise is resolved. If, on the other hand, it returns something else, then that promise will still run, but Shiny won't block waiting for it. This is something that both I and @aronatkins have run into, and it would be helpful if it were better documented in https://rstudio.github.io/promises/articles/shiny.html.
The text was updated successfully, but these errors were encountered: