2
votes

I am developing a R Shiny application involving Twitter data fetching. As the process could last some time I would like to indicate that the application is busy doing something, so the user doesn't thing the page is frozen.

In my case, I store some reactive values this way:

rv <- reactiveValues()
rv$analysisStarted <- FALSE
rv$analysisAvailable <- FALSE

Then, in UI, the user must press an actionButton in order to start processing. Then, I would like to indicate somewhere the Server is working...

  observeEvent(input$analysisButton, {

    rv$analysisStarted <- TRUE
    rv$analysisAvailable <- FALSE

    #Processing Twitter info...

    rv$followersAnalysisStarted <- FALSE
    rv$followersAnalysisAvailable <- TRUE

  })

If, in UI.r, I place a textOutput and create the corresponding output method this way, it does NOT work:

  output$text <- renderText({

    if (rv$analysisStarted) {
      "Server is working..."
    } else if (rv$analysisAvailable) {
     "Your report is ready :) "
    } else {
      "Enter the data to search and press analysisButton"
    }
  })

What I have noticed is when the analysis begins, the label changes to a gray color, but it doesn't update the text until the process is over.

What should be the proper coding of this feature? Is it possible to redraw the text output within observeEvent? Is it possible with the raw shiny library or requires shinyjs, which I am also using?

Any help would be grateful.

1

1 Answers

1
votes

In your case, it would be helpful a progressbar to check the state. This element would be appreciate by your users to indicate the state. Unfortunately, the progress bar would have to code before the functionality. It is a trick, you see a progress bar but this object stops when the function starts.

Here is the tutorial: http://shiny.rstudio.com/gallery/progress-bar-example.html

From my point of view, the progress bar is the best way to inform the web users of the website state but it is not completely perfect. Further you can change the style of the bar with CSS to customize and select your own colors, size...