daattali / daattali/shinycssloaders

Issue with DataTables using withSpinner() showing up if an error occurs instead of clearing

Open
#98 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
CSS
Stars
422
Forks
45
PR merge metrics
No merged PRs in 30d

Description

I have an app that fetches some data and creates a tabular report. While the data is fetching and calculating, the spinner creates a more pleasant UI. However, I've noticed that if an error in the fetch process happens, instead of clearing the DT, it shows up as the last created DT with the error text overlay. Here's an example:

```
library(shiny)
library(DT)
library(shinycssloaders)

ui <- fluidPage(
actionButton("trigger_error", "Trigger an error"),
actionButton("clear_error", "Clear an error"),
tagList(dataTableOutput("mytable"),
uiOutput("extra_info")
) %>% withSpinner(type = 5, color = "#d71635")
)

server <- function(input, output, session) {

error_active <- reactiveVal(FALSE)

observeEvent(input$trigger_error, {
error_active(TRUE)
})
observeEvent(input$clear_error, {
error_active(FALSE)
})

mydata <- reactive({

# pretend computing data takes some time
Sys.sleep(0.2)

if (error_active()) stop("Triggered user error.")

data.frame(x = 1:10,
y = 2:11)
})

output$mytable <- renderDataTable({
req(mydata())

input$clear_error

datatable(mydata(), escape = FALSE)
})

output$extra_info <- renderUI({
req(mydata())
tagList(
h2("Extra information")
)
})

}

shinyApp(ui, server)
```

To trigger, press Clear error 3 or 4 times (I'm not sure why this number, sometimes it occurs at 2). It should appear as the table with the error overlaid:

Image

In my work this is especially a problem since the table shows the last succesful report, while the system should be creating a different report.

I'm using shiny 1.11.1, DT 0.33, shinycssloaders 1.1.0.

Some things I've noticed:
* it seems it's important that the DTOutput is in the tagList, and I can't replicate the error if the spinner's JUST on the dataTableOutput
* renderDataTable()'s expression needs to have some more reactive components, like input$clear_error

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by running the provided Shiny example with DT and shinycssloaders, then reproduce the failure with the spinner wrapped around the tagList containing dataTableOutput and uiOutput. Compare the behavior when renderDataTable() or renderUI() errors; done when an error clears the DataTable instead of leaving the last successful table visible with an error overlay.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
frontend, web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.