How to use future/promises to read rds files in background to decrease initial loading latency in IE11

Hi!

I have an app where there is some initial loading latency in IE11. After posting my issue in shinyapps.io community, I got advised to use future/promises packages and apply this concept in order to load my 3 files in background at the same time. And after reading about async programming, I tried to implement the following:

I have three rds files to read, and then update the choices of selectinput accordingly.

Globally I have:

library(promises)
library(future)

plan(multiprocess)

promise_m <- future( readRDS("www/mouse.rds") )

promise_h <- future(readRDS("www/human.rds"))

promise_d <- future( readRDS("www/drosophila.rds") )

In the server shiny I have:

observeEvent(input$genome, {
  options(future.globals.maxSize=1e9)
  if (input$genome == "mouse"){
    promise_m %>%
      then(function(value){
        updateSelectInput(session = session, inputId = "geneId_mouse", choices = print(value) )
      })
  } else if (input$genome == "human") {
    promise_h %>%
      then(function(value){
        updateSelectInput(session = session, inputId = "geneId_human", choices = print(value))
      })
  } else {
    promise_d %>%
      then(function(value){
        updateSelectInput(session = session, inputId = "geneId_drosophila", choices = print(value))
      })
  }
})

Reading these files cause initial latency in IE11, which makes the app freeze when I deploy it to the shinyapps.io, but locally it works fine. So I need to read these files at the same time in different R processors. But the above code still does not change the loading latency. My question is that how can I modify it or is there a process I should be aware of to solve this? Do I need to change number of CPU or any other settings when I deploy the app? Or is this has something to do with plan(multisession/multoprocess)?

I highly appreciate your advice!

Thank you for your support.

Best Regards,

Karni Bedirian

If your latency is worse with IE11 than, say, Chrome, I think it's unlikely the latency is from the loading and more likely it's from updateSelectInput; IE really hates having thousands of choices shoved down its throat. Luckily there's an extremely easy fix which is to add server=TRUE to your updateSelectInput. This puts the selectInput in a mode where the choices only live on the server and the client just downloads a little at a time in response to queries.

If that doesn't fix the latency please let us know!

3 Likes

Hi.

Thank you for your reply.

It seems updateSelectinput does not take argument server=TRUE, but updateselectizeinput does. When I added server = TRUE to updateSelectinput I got an error 'server argument not used', and when I added it to updateselectizeinput, nothing was changed, choices were kept as NULL initially.

Appreciate your advice.
Thank you
Best Regards,
Karni

Yes, sorry, updateSelectizeInput. Hmmm, that's weird that it didn't work. Does typing in the select input give you any results?

Typing in the selectizeinput does not give me any result, which is very strange. My app is pretty large, and there are many dynamic UI being called in the server. What I want to say is that many things are happening in the background, I don't know if this has anything to do with the issue I am facing.

Thank you for your support!
Best Regards,
Karni Bedirian

Are you pretty sure your updateSelectizeInput is actually being called? Maybe try printing a message right before/after that line of code?