is this a Shiny issue itself? when using future package

I have the below, which is able to display the value in Shiny after some time:

library(promises)
library(future)
plan(multicore)

f_dots <- function() {
  f <- future({
    s <- rnorm(1000000000)
    mean(s)
  }) %plan% multiprocess

  while (!resolved(f)) {
    cat("...")
  }
  cat("\n")
  value(f)
}

output$RowsRuns2 <- renderUI({
  HTML(f_dots())
})

However, when I replaced the f_dots function with my long running process as below:

f_dots <- function() {
   f <- future({
    get_raw_dataset(5001,'2020-01-01','2020-11-01')
  }) %plan% multicore

  while (!resolved(f)) {
    value("...")
  }
  cat("\n")

  value(f)[[1]]
}

it does not display any value in the Shiny output, although I tested on the Console itself, it does has the value:

> f_dots <- function() {
+   f <- future({
+     get_raw_dataset(5001,'2020-01-01','2020-11-01')
+   }) %plan% multicore
+ 
+   while (!resolved(f)) {
+     value("...")
+   }
+   cat("\n")
+ 
+   value(f)[[1]]
+ }
> HTML(f_dots())

63

The output from get_raw_dataset is a list, that is why I am having value(f)[[1]]
Do you have any idea what went wrong? Is this issue comes from Shiny itself? That get_raw_dataset is a function generated from the reticulate package (which brings in the python function into R). But I suppose it is not that issue, as it is able to generate its output as shown above.

Main question is why is it able to show its output at the R terminal console, but it is not able to display inside Shiny.

if this works as provided, but then not when you make the get_raw_dataset 'real' then the problem is your get_raw_dataset (which at the least is a poorly named function if it doesnt get raw datasets but gets numbers like '63'...

library(promises)
library(future)
library(shiny)

plan(multicore)
library(shiny)

ui <- fluidPage(
  uiOutput("RowsRuns2")
)

get_raw_dataset<- function(x,y,z){
  return(63)
}

server <- function(input, output, session) {
  f_dots <- function() {
    f <- future({
      get_raw_dataset(5001,'2020-01-01','2020-11-01')
    }) %plan% multiprocess
    
    while (!resolved(f)) {
      cat("...")
    }
    cat("\n")
    value(f)
  }
  
  output$RowsRuns2 <- renderUI({
    HTML(f_dots())
  })
}

shinyApp(ui, server)

apologized that I did not provide enough background information, which leads to some misleading idea.
yes, that function get_raw_dataset has different outputs, one of which is its raw dataset (8th output).

a=get_raw_dataset(5001,'2020-01-01','2020-11-01')
> a[[1]]
[1] 63
> a[[2]]
[1] 17881
> a[[3]]
[[1]]
[1] 10661

[[2]]
[1] 9

> a[[4]]
[[1]]
[1] 3195447

[[2]]
[1] 7

> a[[5]]
[1] 10661
> a[[6]]
[1] 107
> a[[7]]
[1] 107
> a[[8]]
         dttm               section     decision     lab_x       pressure1           pressure2       pressure3          pressure4   title_run          start_ttms
0   2020-01-08 10:21:00        1234            1       1         405.83300           2.00000           8.00000       421.5000000 RUN20200108075100 2020-01-08 09:22:30
14  2020-01-08 13:03:00        5678            1       1         406.41700           2.00000           8.00000       427.5830000 RUN20200108075100 2020-01-08 09:22:30
28  2020-01-09 01:16:00        9012            1       1           4.50000           8.00000           7.41667         0.0000000 RUN20200109094930 2020-01-08 22:39:30
blah blah....

For my case here, I am just trying to display out the first output, which on the R Console, it is able to show, but NOT inside Shiny itself.
Hope I have clarified.

I am feeling a rather strong sense of deja vu...

library(promises)
library(future)
library(shiny)

plan(multicore)
library(shiny)

ui <- fluidPage(
  uiOutput("RowsRuns2")
)

get_raw_dataset<- function(x,y,z){
  return(63:1)
}

server <- function(input, output, session) {
  f_dots <- function() {
    f <- future({
      get_raw_dataset(5001,'2020-01-01','2020-11-01')
    }) %plan% multiprocess
    
    while (!resolved(f)) {
      cat("...")
    }
    cat("\n")
    value(f)
  }
  
  output$RowsRuns2 <- renderUI({
    HTML(f_dots()[[1]])
  })
}

shinyApp(ui, server)

yes, your code above shows a value of 63. I have thought we should try out return a list like below:

get_raw_dataset<- function(x,y,z){
  return(list(63,17881,10661))
}

which I tested out, and is able to show its correct value at different indexes:

output$RowsRuns2 <- renderUI({
  HTML(f_dots()[[1]])
})

or

output$RowsRuns2 <- renderUI({
  HTML(f_dots()[[2]])
})

But when I comment the function above, and try to get its output from its long-running process, it refuses to show it, though on its R console, it is able to show out, as I have mentioned before.

my bad, so sorry about it, we can close this case... the issue arise out of a missing variable which it cannot find.

This topic was automatically closed 54 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.