呈现数据透视表结果时出错

An error occurred rendering the PivotTable results

我尝试用

创建闪亮的应用程序

rpivotTablenvd3 rcharts

一切正常,但是当我尝试显示数据透视表中的任何图表时 我收到错误

An error occurred rendering the PivotTable results.

但是如果我只使用 rpivotTable 图表在 pivot 中工作,我认为在一个闪亮的应用程序中使用 rpivotTablenvd3 rcharts 时会出现问题。

例子

UI

library(shiny)
library(rCharts)
library(rpivotTable)
shinyUI(fluidPage(
  showOutput('plot1',lib = "nvd3"),
  rpivotTableOutput('pivot1', width = "100%", height = "500px"))  
)

服务器

library(shiny)
library(rCharts)
library(rpivotTable)

df=data.frame(A=c(1:10),B=c(-10:-1),C=c("x",rep(c("x","y","z"),3)))
shinyServer(function(input, output, session) {
  output$pivot1 <- renderRpivotTable({
    rpivotTable(data =df ,
                width="100%", height="500px")
  })

  output$plot1=renderChart2({
    myform <- as.formula(paste('A','~','B'))

    n2 <- nPlot(myform,  group ="C", data = df, type = 'multiBarChart')
    n2$chart(margin = list(left = 100))
    n2$chart(reduceXTicks = F)
    n2$set(width = 800, height = 500) 

    print(n2)
  })
  })

给我

如果我在数据透视表中只使用 rpivotTable 个图表

当我查看 inspect 时,我看到了

TypeError: a.axisTimeFormat.multi is not a function
    at e.i.initParams (c3.min.js:1)
    at e.i.init (c3.min.js:1)
    at new d (c3.min.js:1)
    at Object.k.generate (c3.min.js:1)
    at Object.renderer (c3_renderers.coffee:129)
    at t.fn.pivot (pivot.coffee:546)
    at pivot.coffee:835

有办法解决吗?

包版本:

rpivotTable_0.1.5.7                    
rCharts_0.4.2    
shiny_0.12.2.9005 

谢谢!

正如评论中所指出的,这是由于 n3 库的双重加载。为避免此问题(这更像是一种破解而非修复),您可以在 iframe 中绘制 rcharts 框架以避免 jscss 问题。

要做到这一点,你可以使用 uiOutput/renderUI 用于闪亮部分,并使用 show 输出 rCharts

这是一个例子:

library(shiny)
library(rCharts)
library(rpivotTable)

df=data.frame(A=c(1:10),B=c(-10:-1),C=c("x",rep(c("x","y","z"),3)))

ui <-shinyUI(fluidPage(
        uiOutput('plot1'),
        rpivotTableOutput('pivot1')  
))


server <- shinyServer(function(input, output, session) {
        output$pivot1 <- renderRpivotTable({
                rpivotTable(data =df)
        })

        output$plot1=renderUI({
                myform <- as.formula(paste('A','~','B'))
                n2 <- nPlot(myform,  group ="C", data = df, type = 'multiBarChart')
                n2$chart(margin = list(left = 100))
                n2$chart(reduceXTicks = F)
                HTML(paste(capture.output(n2$show('iframesrc', cdn = TRUE)), collapse = '\n'))

        })
})

shinyApp(ui,server)