Hi, I am running the following code, which has 2 buttons, one is for executing Sleep(10) and another to read a csv and populate a datatable. I am keeping the first button execution within future and second button function as usual operation. However when I click on both buttons one after the another, the second button still seems to wait for the Sleep functionality to complete. Any reason or issue with the code below why it is not executing in parallel or async ?
library(promises)
library(shiny)
library(future)
plan(multiprocess)
longRunningFunction <- function(value) {
Sys.sleep(10)
return(value)
}
readFile <- function() {
x <- data.frame()
x=read.delim("./sampledata.txt",header=FALSE,sep=",")
}
ui <- fluidPage(
titlePanel("Async with Promises"),
sidebarLayout(
sidebarPanel(
actionButton("long", "Long running function"),
actionButton("tblButton", "Display table")),
mainPanel(
textOutput("txt"),
shiny::dataTableOutput("result")
)
)
)
server <- function(input, output,session) {
observeEvent(input$long, {
timedelay <- future(longRunningFunction(5))
output$txt <- renderText({
timedelay %...>% print()
})
})
observeEvent(input$tblButton, {
tbl <- readFile()
output$result <- shiny::renderDataTable({
tbl
})
})
}
# Run the application
shinyApp(ui = ui, server = server)