Demo use of future_promise and zeallot not working

I am experimenting with Shiny and async programming in the hopes of using it in a larger, more complex, public application.

In this example, I thought that unlist() would wait until the value of v1 is returned because of the use of future_promise and the promise pipe, %...>% .

However, I get the error:

Error in unlist: object 'v1' not found

How can I get this demo code to work?

app.R

library("zeallot")
library("shiny")
library("primes")
library("future")
library("promises")
library("tidyverse")

plan(multisession)

source("/home/law/whatbank_multicore_test/src/expensive_calc.R")

ui <- fluidPage(
  actionButton("do", "Do Expensive Calc"),
  textOutput("text")
)

server <- function(input, output, session) {
  observeEvent(input$do, {
      output$text <- renderText({
        future_promise(zeallot::`%<-%`(c(v1, v2), expensive_calc()), seed = TRUE) %...>% 
          {
            tmp <- unlist(v1)
          }
      })
  })
}

shinyApp(ui, server)

expensive_calc.R

expensive_calc <- function(){
  
  min <- 10000
  max_num <- sample(80000:210000, 1)
  rap <- ruth_aaron_pairs(min, max_num, distinct = FALSE)
  
  list(rap, 11)
}

move the use of zealot pipe to inside the future_promise curly brackets

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.