I am trying to figure out async R shiny and there is something fundamental I do not understand.
See my code
library(shiny)
library(future)
library(promises)
library(dplyr)
plan(multiprocess)
ui = shinyUI(fluidPage(
sidebarLayout(
sidebarPanel(),
mainPanel(
tableOutput("table"),
tableOutput("table2")
)
)
))
server = shinyServer(function(input, output) {
filtered_df <- reactive({
future({
Sys.sleep(10)
read.csv("https://rstudio.github.io/promises/data.csv")
}) %...>%
filter(state == "NY") %...>%
arrange(median_income)
})
output$table <- renderTable({
filtered_df()
})
output$table2 <- renderTable({
head(mtcars)
})
})
shinyApp(ui, server)
I run a Sys.sleep(10) to stall the process. In the meanwhile I want to render a second table under the first.
But somehow nothing is being loaded on my screen until the filtered_df is computed.
I am expecting the async code to switch to the next rendering while it is computing the values for the first table.
Why is it now the case? How can I correct this?