You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

R Shiny中DT::dataTableProxy与SearchPanes扩展兼容问题问询

R Shiny中DT::dataTableProxy与SearchPanes扩展兼容问题解析

问题根源

  • SearchPanes扩展依赖Select扩展;
  • Select扩展要求设置DT::renderDT(server = FALSE)参数;
  • DT::dataTableProxy不支持客户端模式,会触发DT错误。

测试代码

library(shiny)
library(shinydashboard)
library(tidyverse)

ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(
    shiny::selectInput("rows", label = "Rows", choices = 1:nrow(mtcars)),
    shiny::actionButton("new", label = "New Data")
  ),
  dashboardBody(DT::dataTableOutput("cars"))
)

server <- function(input, output) { 
  rows <- reactive({ input$rows })
  output$cars <- DT::renderDataTable(server = FALSE, {
    expr = DT::datatable(
      data = mtcars |> head(rows()) 
      #,
      #extensions = c("SearchPanes", "Select", "Buttons"),
      #options = list(
      #  dom = "Btip",
      #  buttons = list("searchPanes")
      #)
    )

  })
  
  dtProxy <- DT::dataTableProxy("cars")
  
  observeEvent(input$new, label = "Observe button proxy update", {
    doubledata <- bind_rows(mtcars, mtcars)
    DT::replaceData(proxy = dtProxy, 
                    data = doubledata,
                    resetPaging = FALSE)
  })
}

shinyApp(ui, server)

测试现象

  • 设置server = FALSE时,点击「New Data」按钮会触发DT警告:DataTables warning: table id=DataTables_Table_0 - Invalid JSON response. For more information about this error, please see http://datatables.net/tn/1;
  • 移除server = FALSE参数后,dataTableProxy可正常运行;
  • 取消SearchPanes相关代码注释后,搜索面板能显示但无实际筛选功能,同时系统提示需设置select='none'。

参考资料

  • RStudio DT扩展官方文档
  • Matt Herman的SearchPanes教程

内容的提问来源于stack exchange,提问作者kraggle

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.03 01:40:20