3

Is there a possibility in R Shiny to replace a plot with a "loading" message while additional data is loading? I am using a big dataset in my app and since not all data is always necessary, I split the data in two parts and initially load only a smaller sample.

Only when the full dataset is chosen in a dropdown menu, I load the full sample. Since loading takes some time and freezes the plot, I would like to show a message instead and show the plot only when the loading is done. Example:

library(shiny)

ui <- fluidPage(
  selectInput("select_length","Length",choices = c("Short","Long"), multiple= FALSE, selected = "Short"),
  plotOutput("hist")
)

server <- function(input, output){
  rv <- reactiveValues()
  rv$df <- c(1,2)

  observeEvent(input$select_length,{
    Sys.sleep(5)
    df_new <- c(3,4)
    rv$df <- c(rv$df, df_new)
    },
    once = TRUE,
    ignoreInit = TRUE
  )

  output$hist <- renderPlot({
    barplot(rv$df)
  })
}

shinyApp(ui = ui, server = server)

I would like to show a plot with a simple "loading" message while the additional data is being loaded, e.g.:

plot(c(0, 1), c(0, 1), ann = F, bty = 'n', type = 'n', xaxt = 'n', yaxt = 'n')
text(x = 0.5, y = 0.5, paste("Data is loading..."), cex = 1.6, col = "black")
4

3 Answers 3

1

You might like the ShinyBS package. I've used it for alerts when loading data before and it works great (it also looks fancy).

Here's an example of my usage....Example

This was the code used to create the alert, it's fairly simple. The user can exit it or you can call to delete as detailed below.

Server:

createAlert(session, 'upload_complete',title = 'Data Import Complete', content = 'You may continue to the other tabs', alertId = 'alert_delete', append = FALSE)

UI:

mainPanel(
....
bsAlert('upload_complete'),
)

Call to delete (in server)

closeAlert(session,'alert_delete')
Sign up to request clarification or add additional context in comments.

Comments

1

I suggest to use library(shinycssloaders).

is very simple and professional.

  1. library(shinycssloaders)
  2. options like eg: options(spinner.color="#0275D8", spinner.color.background="#ffffff", spinner.size=.5)
  3. add the loader with withSpinner(Output method(objectname), type = 1-8)

https://www.listendata.com/2019/07/add-loader-for-shiny-r.html

Comments

0

would it be acceptable to show a progress bar while the additional data is loading? Shiny RStudio show an example for displaying a plot - http://shiny.rstudio.com/gallery/progress-bar-example.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.