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

Shiny页面渲染DataTable报错:pillar_num() not supported 求助

问题

以下Shiny代码用于输出贝叶斯回归系数的DataTable,在旧电脑运行正常,但新电脑报错:DataTables warning: table id=DataTables_Table_6 - pillar_num() not supported,求解决建议。

代码

ui <- mainPanel(
      DT::dataTableOutput("bayes_model_coefficient")
    )

bayes_model_coefficient <- eventReactive(input$model_runModel_2,{
    if (input$model_runModel_2 == 0){
      return()
    }
    coefff <- brms::fixef(bayes_model_re())[,"Estimate"]
    bayes_coef <- data.frame(
      Variable = names(coefff),
      Coefficient = format(round(fixef(bayes_model_re())[,"Estimate"], digits=2), big.mark=",", scientific = FALSE),
      Est.Error = format(round(fixef(bayes_model_re())[,"Est.Error"], digits=2), big.mark=",", scientific = FALSE),
      t.value = format(round(fixef(bayes_model_re())[,"Estimate"]/fixef(bayes_model_re())[,"Est.Error"], digits = 2), big.mark=",", scientific = FALSE),
      Rhat = round(summary(bayes_model_re())$fixed$Rhat, digits = 4),
      row.names = NULL
    )
    
    bayes_coef_copy <- bayes_coef 
    bayes_coef$actualSign <- ifelse(coefff < 0, 1, 2) 
    prior_inf <- values$fixCoef_2
    if(is.null(prior_inf)) {
       prior_inf <- data.frame(prior = NA, coef = NA)
     }
    prior_inf <- subset(prior_inf, select=c("prior", "coef"))
    bayes_coef <- merge(bayes_coef, prior_inf, by.x="Variable", by.y="coef", all.x=TRUE)
    names(bayes_coef) <- c("Variable",
                         "Coefficient",
                         "Est.Error",
                         "t.value",
                         "Rhat",
                         "actualSign",
                         "prior")
    
    bayes_coef <- bayes_coef[!is.na( bayes_coef$Variable),]
  
    bayes_coef <- datatable(bayes_coef,
                          rownames=FALSE,
                          options=list(ordering=FALSE,
                                       paging=FALSE,
                                       info=FALSE,
                                       columnDefs = list(list(targets=c("actualSign"), visible=FALSE)))) %>% 
      formatStyle("t.value", color=styleInterval(-0.1, c("red", "black"))) %>% 
      formatStyle("Coefficient","actualSign", 
                  color=styleEqual(c(1,2),c("red","black")))
                          
    return(list(bayes_coef = bayes_coef, bayes_coef_copy = bayes_coef_copy))
    
  })

output$bayes_model_coefficient <- DT::renderDataTable({
     bayes_model_coefficient()$bayes_coef
   })

解决建议

  • 调整包版本兼容:该报错核心原因是pillar包版本过高,pillar 1.9.0及以上新增了pillar_num类,旧版DT无法识别。两种处理方式:
    • 降级pillar包:运行install.packages("pillar", version="1.8.1")(选择适配旧版DT的稳定版本)
    • 升级DT包:运行install.packages("DT"),新版DT已适配pillar的新数据类型
  • 强制转换数据类型:在生成bayes_coef数据框后,将所有列转换为基础R类型,避免pillar特殊类型传入DT,可在merge操作后添加:
    bayes_coef <- as.data.frame(lapply(bayes_coef, as.vector))
    
  • 优化代码减少重复调用:原代码多次调用bayes_model_re(),既降低效率也可能引入类型问题,建议先缓存模型结果,后续从缓存提取数据,比如:
    model_result <- bayes_model_re()
    coefff <- brms::fixef(model_result)[,"Estimate"]
    fixef_result <- brms::fixef(model_result)
    summary_fixed <- summary(model_result)$fixed
    

内容的提问来源于stack exchange,提问作者Ozgur Alptekın

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.28 14:10:31