ITADN
rstudio/DT/Issues

Unecessary "Datatables warning" alert when creating a DT with new data and same number of columns

#1179OpenMkranj 创建于 2025-09-03
M
Mkranjcommented
I'm writing an app that creates certain reports at the click of a button. When a new report has the same number of columns as the previous one, DT throws an alert about how *column name from old data* is not present in *new data*, that needs to be clicked through. After that, it creates the correct table without issue! This obviously makes for poor UX since it seems something has gone wrong when, in fact, everything went OK. I'm pretty sure the issue is that the DTOutput() function is a part of a renderUI() call. It doesn't seem likely I can move away from this since I need to make some checks before displaying or hiding the table. Here is a simplified version as a reproducible example: ``` library(shiny) library(DT) ui <- fluidPage( actionButton("change_col", "Change column names"), uiOutput("custom_ui") ) server <- function(input, output, session) { output$custom_ui <- renderUI({ # this req() simulates that my app needs to check some reactive values to # determine whether to show or hide the table req(input$change_col) DT::DTOutput("my_table") }) output$my_table <- renderDT({ req(input$change_col) my_data <- iris # the number of columns is always the same, # but the column names differ each run new_colnames <- paste(colnames(iris)[1:5], rnorm(5) ) colnames(my_data)[1:5] <- new_colnames DT::datatable(my_data) }) } shinyApp(ui, server) ``` Do you have any suggestions as how to avoid this alert? One solution I've found is to add a callback that disables DT alerts (adding `callback = DT::JS("$.fn.dataTable.ext.errMode = 'none';")` to the datatable() call). I'm not happy with that since if there were any legitimate alerts, this would disable them too.
0 条评论