rstudio / DT

R Interface to the jQuery Plug-in DataTables
https://rstudio.github.io/DT/
Other
587 stars 184 forks source link

DT 0.31 breaks previous 'ignore colnames' behavior during `replaceData()` #1108

Closed mmuurr closed 5 months ago

mmuurr commented 6 months ago

I've confirmed commit b42dd91 (part of v0.31) causes a breaking change.

In previous versions, when pushing data to a DT via replaceData(), only column order was used (i.e. colnames were ignored). With b42dd91, colnames are now required (assuming the original 'shell' table being proxied has colnames) and replaceData() calls now fail when any expected colname is missing, triggering a window.alert() on the client.

Perhaps matching on colnames is a perfectly fine API change, but neither the release notes nor the replaceData() docs highlight this change as a new requirement (i.e. a breaking change). I suspect many applications (like some of mine :-)) will fail surprisingly after the DT update.

The below works with 8f6bfd1d19c35a628e4382f30cc98c353b2d97cd but fails with b42dd91caa4933f76e1cb459b1b2a2eaead92d0f.

library(shiny)
library(DT)

UI <- fluidPage(dataTableOutput("the-table"))

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

  output[["the-table"]] <- renderDataTable({
    datatable(
      data = iris[0,],
      rownames = FALSE
    )
  })

  dt_proxy <- dataTableProxy("the-table")

  observe({
    replaceData(dt_proxy, unname(iris), rownames = FALSE)  ## `unname` to trigger the (FE) error
  })
}

runApp(shinyApp(UI, SERVER))

By filing an issue to this repo, I promise that

I understand that my issue may be closed if I don't fulfill my promises.

yihui commented 5 months ago

Sorry about that! It's indeed a bug that I failed to realize. Should be fixed now.

You can install the development version via

remotes::install_github('rstudio/DT')