8

Shiny is our internal BI tool. For our Shiny apps, we load data before shinyServer running:

load("afterProcessedData.RData")
# or dt = fread("afterProcessedData.csv")

shinyServer(function(input, output, session){ ...

However, some of apps are loading big files and they take up to 30s to load up. Many users, when they open a page, don't know whether the page is broken since it is stuck when it is loading. They may close it or click filters, which may cause an error. In this case, a progress bar will be very helpful. I notice withProgress() may help but it has to be inside reactive() or renderXx().

One way I can do is to have laod() warpped with reactive() inside the shinyServer(function(input, output, session){ but my concern is it will slower the performance. And my users very care about the responsive performance.

Any suggestions for this situation?

Edit: I guess there is not an easy way to do this. I have another thought. Maybe I can show a text on the screen saying 'the data is loading', but I have to make it disappear after the first table gets show up. However, I don't know how to set up the condition. Below is my code showing first table:

dashboardBody(
fluidRow( 
  tabBox(width = 12,
         tabPanel("Summary",
                  dataTableOutput("data1")),

Thank you in advance!

Z. Zhang
  • 501
  • 8
  • 20
  • Curious, why `withProgress()` inside a `reactive ()` or `render()` a problem ? . Even though, I am not happy with the kind status bar it displays, but it works OK for me when I wrap `withProgress` in all my `render()` functions . – user5249203 Feb 09 '16 at 21:17
  • Additionally, how about wrap your data loading functions with examples shown in these [SO solutions](http://stackoverflow.com/questions/4754996/showing-a-status-message-in-r), and then `render` that out on Shiny `withProgress()` ? – user5249203 Feb 09 '16 at 21:21
  • This works for me. `output$Ref_output <- DT::renderDataTable(withProgress( message = 'Processing the query', value = 5, expr = { DT::datatable(reference.table(), selection = 'multiple')` With some changes to CSS file the progress bar is thicker and in red color than default one. – user5249203 Feb 09 '16 at 21:24
  • @user5249203 thanks for your answer. My concern of having `load()` in the `reactive()` is that it will slow down the performance since each change will call a `load()`. The second solution with `SO solutions` somehow makes `load()` 3 times longer, which will be blamed by clients. – Z. Zhang Feb 09 '16 at 21:42
  • If this load is in a global variable then why should it `load` at every session? for everything else you can and should use `withProgress()` also desable buttons while people wait with `shinyjs` package so they dont click on anything until its fully loaded – Pork Chop Feb 10 '16 at 08:37

2 Answers2

5

Even though I am still interested in knowing how to add process bar for load(), I have implemented the alternative solution, which is good for now. It has a text saying 'the data is loading...' on the page, and it will disappear after first table shows up.

#server.R   firstData is a reactive function to get the data for 1st table
  output$firstTable = reactive({
return(is.null(firstData()))
})
#ui.R
      conditionalPanel(
    condition = "output.firstTable",
    box(width = 12,
           h1("The data is loading...")
        )
  )
Z. Zhang
  • 501
  • 8
  • 20
  • 1
    New aspects. Instead of loading the complete `.rdata`, you can save each object and read them separately. It is efficient and faster. Check `readRDS` . Now, there is an easy way to achieve spinner or likewise in Rshiny . `DT::dataTableOutput(outputId = 'table')%>% withSpinner()` – user5249203 Oct 05 '17 at 15:07
3

To reference the intriguing note from @user5249203 , withSpinner() looks to be a useful option for this functionality and is a part of the shinycssloaders package. I have not used myself, but it is definitely an intriguing package that happens to be on CRAN and to have some nice examples: https://andrewsali.shinyapps.io/example/

cole
  • 1,737
  • 2
  • 15
  • 21