3

i have not found the solution for my question about ProgressBar in Shiny for loading the data from database. My Shiny App is connected to database and the user directly gets the data from there (as my SQL Query is reactive, the amount of the data varies). Sometimes the data is quite big and loading it takes some time. The user does not know if something is going on or the app got "stuck". I implemented in my app (in output$tabelle <- DT::renderDataTable({...) the easiest possible process indicator but it seems to not be enough:

progress <- shiny::Progress$new()

        on.exit(progress$close())

        progress$set(message = "Processing", value = 0)

The user still gets bit confused.

I would like to have smthg like this (showing a status message in R) using ?tcltk::tkProgressBar:

enter image description here

pb <- tkProgressBar("test progress bar", "Some information in %",
        0, 100, 50)
Sys.sleep(0.5)
u <- c(0, sort(runif(20, 0 ,100)), 100)
for(i in u) {
    Sys.sleep(0.1)
    info <- sprintf("%d%% done", round(i))
    setTkProgressBar(pb, i, sprintf("test (%s)", info), info)
}
Sys.sleep(5)
close(pb)

with some percentage valuating the progress of data loading from database.

I do not know how i can use it inside my shiny app. Any ideas will be helpful.

Thanks in advance!

*some simple app:

library("shiny")
library("DT")
shinyApp(
  ui = fluidPage(DT::dataTableOutput('tbl')),
  server = function(input, output) {
    output$tbl = DT::renderDataTable(
      iris)
  }
)
Community
  • 1
  • 1
Mal_a
  • 3,670
  • 1
  • 27
  • 60
  • Have you already found a solution to this or still looking for it? :) – Michal Majka Aug 09 '16 at 22:19
  • Hey You :) Well not really this what i wanted. I have used smthg like that: `output$tabelle <- DT::renderDataTable({ withProgress(message = 'Processing...', value = 0, { for (i in 1:10) { incProgress(1/30) Sys.sleep(0.25) } datatable(...` However this does not provide the percentage and either does not correspond much to the process of loading data as we need to set the `incProgress` – Mal_a Aug 10 '16 at 05:21
  • Ok, I'll take a look at it in a free time because it is a very interesting problem – Michal Majka Aug 10 '16 at 05:52
  • hahah Well Thank You very much! Take Your time – Mal_a Aug 10 '16 at 05:53
  • You probably load data with some button, right? – Michal Majka Aug 10 '16 at 06:04
  • Yes exactly `actionButton("button1", "Auswaehlen")` – Mal_a Aug 10 '16 at 06:40

1 Answers1

9

Probably the easiest way is to use a package shinysky which offers busyIndicator. You won't get a progress bar but a loading animation in the middle should do work too. You can also customise it by setting the text to show, gif and the time after which the indicator should be shown. (by default after one second).


Full example:

library("shiny")
library("DT")
library("shinysky")

shinyApp(
  ui = fluidPage(
    busyIndicator(),
    h3("Test"),
    hr(),
    DT::dataTableOutput('tbl')
  ),
  server = function(input, output) {
    output$tbl = DT::renderDataTable({
     data.frame(x = rnorm(7000000), y = runif(7000000))
    })
  }
)
Michal Majka
  • 5,332
  • 2
  • 29
  • 40