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")