rstudio/DT

Issue using `replaceData()` with `dataTableProxy()`

gadenbuie opened this issue · 4 comments

AFAICT, this issue was introduced in #1096. We found this in the nightly shiny tests, which started to fail the day after the day #1096 was merged (and then it took me a little bit to triage and track down the issue).

Here's a small reprex app:

library(shiny)
library(DT)

ui <- fluidPage(
  DTOutput("table"),
  actionButton("inc", "Increment")
)

server <- function(input, output, session) {
  x <- reactiveVal(0L)

  df <- reactive({
    data.frame(value = x())
  })

  output$table <- renderDT({
    DT::datatable(
      isolate(df()),
      rownames = FALSE,
      options = list(dom = "t", ordering = FALSE)
    )
  })

  observeEvent(input$inc, {
    message("incrementing x: ", x(), " -> ", x() + 1L)
    x(x() + 1L)
  }, ignoreNULL = TRUE)

  observeEvent(x(), {
    req(x() > 0)
    message("replacing table data")
    replaceData(dataTableProxy("table"), df())
  })
}


shinyApp(ui, server)

The expected behavior is for the table to be a single column (value) with a single row. When clicking on the Increment button, the value should increment by one, using replaceData(dataTableProxy("table"), df()).

The current behavior I'm seeing is that the app starts as expected

image

but then after clicking the increment button to update the data, the table shows no rows.

image

stla commented

It works if we set rownames=FALSE:

replaceData(dataTableProxy("table"), df(), rownames = FALSE)
yihui commented

Right, if the original table was rendered with rownames = FALSE, the new data should also use rownames = FALSE when replacing the old data.

I've tested CRAN releases 0.30 and 0.29. The problem doesn't seem to be new, i.e., both CRAN versions can reproduce the problem. I don't know why it didn't happen before...

yihui commented

@gadenbuie Could you check if rownames = FALSE works? Thanks!

@yihui it resolves the issue in the reprex! It didn't resolve the new issue in our test apps, but I realized the test app used replaceData(dataTableProxy("table"), x()) (replacing the table with a value, not a data frame), so maybe that was unintentionally supported until recently. Anyway, I've updated our test app with both fixes and I think we can consider this resolved. Thanks all!