Progress Bar Not Showing

1,558 views
Skip to first unread message

Glen DePalma

unread,
Sep 2, 2013, 2:50:30 AM9/2/13
to shiny-...@googlegroups.com
I tried implementing the progress bar from the shinyIncubator package but I don't see it.  There is a delay in the plot so I know it's running  through the for loop but I don't see the progress indicator (I see the progress in the R console too), no errors are reported and the plot does eventually show.

server.R

shinyServer(function(input, output, session) {
  output$plot <- renderPlot({
    withProgress(session, min=1, max=15, {
      setProgress(message = 'Calculation in progress', detail = 'This may take a while...')
      for (i in 1:15) {
        print(i)
        setProgress(value = i)
        Sys.sleep(0.5)
      }
    })
    plot(cars)
  })
})


ui.R

shinyUI(bootstrapPage(
  plotOutput("plot")
))

Jonathan

unread,
Sep 3, 2013, 5:42:06 PM9/3/13
to shiny-...@googlegroups.com
I was going to say that I was having the same problems, but revisiting an old thread that I had started, it seems like it works.

Make sure to add "progressInit()" inside your ui.R, within the shinyUI function. I believe it is not mentioned in the help files.

Once the bugs are worked out, I am looking forward to the progress bar eventually making its way into the official Shiny release.

Jonathan

Glen DePalma

unread,
Sep 4, 2013, 2:27:14 AM9/4/13
to shiny-...@googlegroups.com
Thanks that worked!

Elodie C

unread,
Oct 1, 2013, 10:58:29 AM10/1/13
to shiny-...@googlegroups.com
Hi, 

I have the same problem : I don't see the progress bar.

I add "progressInit()" function inside my ui.R.

I developed in Shiny local Server on ubuntu 12.04 and Chrome.

Server.R
library(shiny)
library(shinyIncubator)

shinyServer(function(input, output,session) {
    output$test <- renderPlot({
    withProgress(session, min=1, max=15, {
 setProgress(message = 'Calculation in progress', detail = 'This may take a while...')
 for (i in 1:15) {
   print(i)
   setProgress(value = i)
   Sys.sleep(0.5)
 }
})
    plot(1,1)
    })
})

ui.R

library(shinyIncubator)
shinyUI(pageWithSidebar(

.......


  # Show the caption and plot of the requested variable against mpg
  mainPanel(

    tabsetPanel(
 tabPanel("test1",plotOutput("test")),
           progressInit(),
           tabPanel("test2",plotOutput("test")),
)
  )
))


I installed shinyIncubator package with this command line : 

sudo su - -c "R -e \"devtools::install_github('shiny-incubator', 'rstudio')\""

Joe Cheng

unread,
Oct 1, 2013, 12:08:13 PM10/1/13
to shiny-...@googlegroups.com
progressInit() can be almost anywhere in the UI--but not directly under a tabsetPanel, which expects its direct descendants to be instances of tabPanel and nothing else. I think if you move progressInit to be directly under mainPanel it'll start working.


--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

ZJ

unread,
Oct 1, 2013, 12:24:06 PM10/1/13
to shiny-...@googlegroups.com
would the code inside output$test even run? Seems like it needs some input source?

ZJ

unread,
Oct 1, 2013, 12:24:49 PM10/1/13
to shiny-...@googlegroups.com
try this runGist("6781097")

Elodie C

unread,
Oct 2, 2013, 4:20:01 AM10/2/13
to shiny-...@googlegroups.com

Yes the code inside output$test work

Elodie C

unread,
Oct 2, 2013, 4:36:53 AM10/2/13
to shiny-...@googlegroups.com

Thanks a lot ZJ and Joe Cheng.

A progressBar is now shown in my shiny app. I want to use this progress bar in order to indicate at user that getting data is quite long sometime.
In this function, I must estimate calculation time but it's depend user choices and data loading. How can I estimate the "max value" in function withProgess() ? 

How can i indicate at user while data are not ready, a progressBar is shown during all calculation time ? 

Server.R

output$table <- renderTable({
      withProgress(session, min=1, max=20, {
 setProgress(message = 'Calculation in progress', detail = 'This may take a while...')
 for (i in 1:20) {
   print(i)
   setProgress(value = i)
   Sys.sleep(0.5)
 }
})
data <- mydata()
data_sort <- data[order(data[,3],decreasing=FALSE),]
head((data_sort),n=15)
    },include.rownames=FALSE)

Joe Cheng

unread,
Oct 2, 2013, 6:35:55 PM10/2/13
to shiny-...@googlegroups.com
Determining the max value is completely up to the user. However if you can't tell, you can just not specify anything and just call setProgress(message="..."), in which case just the message will update and not the bar.


--

Elodie C

unread,
Oct 3, 2013, 4:38:09 AM10/3/13
to shiny-...@googlegroups.com

I thinks it's not a good solution : the progressbar must be shown during calculation time, and calculation time is dependent of my function mydata() (function to get data). 
So if I want to use this code, I must estimate once the calculation time and give this time in max value.
When calculation time is shorter than the max time, the progressBar is present and says at user "you must wait " but data are also present.
If I don't estimate correctly the max calculation time, the progressbar says at user "calculation is finish" but it's not the case.

Joe Cheng

unread,
Oct 3, 2013, 11:59:01 AM10/3/13
to shiny-...@googlegroups.com
You could set the min/max value from 0 to 1, and then send fractional units.

withProgress(session, min=0, max=1, {
  setProgress(message = "Loading user data...")
  workToDo = loadUserData()
  # Let's say we normally expect the user data loading to take 20% of the total time
  setProgress(value = 0.2, message = "Calculating...")
  jobLength = length(workToDo)
  for (i in 1:jobLength) {
    # Do work
    setProgress(0.2 + (i / jobLength))
  }
})

Jin Rou New

unread,
Oct 7, 2013, 3:59:32 AM10/7/13
to shiny-...@googlegroups.com
Dear Joe,

I'm still not very clear about how the progress bar works, so pardon me if this is a very elementary question!

So say I have something like this in my server.R code:

GetResults <- reactive ({
  results <- RunModel(input$data) # function that runs model and spits out results and takes very long to run
  return(results)
)}

output$log <- renderChart({
  GetResults()
}

Where should the withProgress code go? Thanks!

Joe Cheng

unread,
Oct 7, 2013, 7:41:44 PM10/7/13
to shiny-...@googlegroups.com
The withProgress can go around or within the call to RunModel. If you want fine-grained progress, there will need to be calls to setProgress within your RunModel code.

Jin Rou New

unread,
Oct 8, 2013, 6:28:24 AM10/8/13
to shiny-...@googlegroups.com
Hi Joe,

Was getting errors because I left the return(results) statement outside of the withProgress call, but it's working great now, thanks!

Elodie C

unread,
Oct 14, 2013, 6:11:15 AM10/14/13
to shiny-...@googlegroups.com
Hi, 

It works fine.

Here is my code : 

Server.R : 

shinyServer(function(input, output,session) {

    checkmydata <- reactive({
      if((input$mydataset=="Curie" & input$category=="cl") || (input$mydataset=="Curie" & input$category=="clx")){
return("cl")
      }else if(checkgene(getannot(input$mydataset),toupper(input$genesymbol))=="not ok"){
return("gene")
      }else{
      return("ok")
      }
    })

    getmydata <- reactive({
    withProgress(session, min=0, max=1, {
setProgress(message = "Loading user data...")
# Let's say we normally expect the user data loading to take 20% of the total time
setProgress(value = 0.2, message = "Calculating...")
dataCorr <- getCorrData(dataset=input$mydataset,g=input$genesymbol,cat=input$category,m=input$meth)
jobLength = 10
for (i in 1:jobLength) {
 # Do work
 setProgress(value = i)
}
return(dataCorr)
      })
    })

    output$dataFAILED1 <- renderText({
      data <- checkmydata()
      if(data=="cl"){
      return("Information message : Not Cell-lines and Xenogreffe samples for U95A-Av2 dataset")
      } else  if(data=="gene"){
      return("Information message : Gene symbol is not present on this array")
      } else {
      return(toupper(input$genesymbol))
      }
    })
    output$dataFAILED2 <- renderText({
      data <- checkmydata()
      if(data=="cl"){
      return("Information message : Not Cell-lines and Xenogreffe samples for U95A-Av2 dataset")
      } else  if(data=="gene"){
      return("Information message : Gene symbol is not present on this array")
      } else {
      return(toupper(input$genesymbol))
      }
    })

    output$tableCorr <- renderTable({
      dataOK <- checkmydata()
      if (dataOK!="ok"){
return(NULL)
      }
      data <- getmydata()
      data_sort <- data[order(data[,3],decreasing=TRUE),]
      head(data_sort,n=15)
    },include.rownames=FALSE)

    output$tableACorr <- renderTable({
      dataOK <- checkmydata()
      if (dataOK!="ok"){
return(NULL)
      }
      data <- getmydata()
      data_sort <- data[order(data[,3],decreasing=FALSE),]
      head((data_sort),n=15)

    },include.rownames=FALSE)

    output$downloadData <- downloadHandler(
filename = function() { paste(toupper(as.character(input$genesymbol)), '.csv', sep='') },
content = function(file) {
 data <- getmydata()
 data <- data[order(data[,3],decreasing=TRUE),]
 write.csv(data, file,row.names=FALSE)
}
    )

})


ui.R : 

shinyUI(pageWithSidebar(

  # Application title
  headerPanel("Genes Correlation"),

  # Sidebar with controls to select the variable to plot against mpg
  # and to specify whether outliers should be included
  sidebarPanel(
   selectInput(inputId="mydataset",
label="Choose a dataset :",
choices= c("U95A-Av2"="Curie","U133Plus2"="CIT","AffyHuEx"="Exon"),
selected="U95A-Av2",multiple=FALSE),

    radioButtons(inputId="category",
 label="Choose a category :",
 choices= c("All Tumours"="al","Muscle Invasives Tumours"="mi","Non Muscle Invasives Tumours"="nmi","Cell-lines (only for U133Plus2 dataset)"="cl","Cell-lines and Xeno (only for AffyHuEx dataset)"="clx","Basal-like Tumours"="bl","Non Basal-like Tumours"="nbl","FGFR3*"="fgfr3mut","FGFR3wt"="fgfr3wt","MRES+"="mres","MRES-"="nmres","CIS+"="cis","CIS-"="cis")),
    textInput("genesymbol", "Your Favorite Gene : ", 'FGFR3'),
    radioButtons("meth", "Correlation Method :",
      list("Pearson" = "pearson","Spearman" = "spearman")
    ),
  br(),
    submitButton("Submit Choices !!!"),
    br(),
    downloadButton('downloadData', "Download CSV File" )
  ),

  # Show the caption and plot of the requested variable against mpg
  mainPanel(
    progressInit(),
    tabsetPanel(id="myPanel",
 tabPanel("Correlated genes",h3(textOutput("dataFAILED1")),tableOutput("tableCorr")), 
 tabPanel("Anti-correlated genes",h3(textOutput("dataFAILED2")),tableOutput("tableACorr"))
)
  )
))

Tim Jacobs

unread,
Apr 19, 2014, 2:07:09 PM4/19/14
to shiny-...@googlegroups.com
Is there a way to change the location of the displayed progress message?

Joe Cheng

unread,
Apr 19, 2014, 2:26:07 PM4/19/14
to Tim Jacobs, shiny-...@googlegroups.com
Not at the moment. Where do you want to move it to?

Sent from Mailbox


On Sat, Apr 19, 2014 at 11:07 AM, Tim Jacobs <twja...@gmail.com> wrote:

Is there a way to change the location of the displayed progress message?

--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.


John Harrison

unread,
Apr 19, 2014, 2:29:24 PM4/19/14
to shiny-...@googlegroups.com, Tim Jacobs
You can change its location using css. There is an example https://gist.github.com/johndharrison/9578241 which moves the progress message to the middle of the screen.

Tim Jacobs

unread,
Apr 19, 2014, 2:42:49 PM4/19/14
to shiny-...@googlegroups.com
@John, @Joe, thanks for the quick replies. I'll give John's solution a try on Monday and report back.

Tim Jacobs

unread,
Apr 21, 2014, 8:24:36 AM4/21/14
to shiny-...@googlegroups.com
John's solution works as long as I use includeCSS instead of the tags$link() function. The tags$link() function constructs an html page that looks for the css file off of the root of the server which causes a file not found error with runApp(). The includeCSS puts the css in-line in the html.

As a side note, the reason I needed to move the location of the progress message box is that I use a bootstrap navbar in my app. The navbar occluded the message box.

John Harrison

unread,
Apr 21, 2014, 8:52:21 AM4/21/14
to shiny-...@googlegroups.com
Hi Tim,

Yes it is unclear from the gist that the styles.css file needs to be placed in a www/ folder in your app directory.

John
Reply all
Reply to author
Forward
0 new messages