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
相关产品推荐
相关产品推荐

