【问题标题】:R crashes when trying to add a plot on a powerpoint template尝试在 powerpoint 模板上添加绘图时 R 崩溃
【发布时间】:2017-05-31 09:57:04
【问题描述】:

我使用 R 和闪亮的库开发了一个仪表板,其中显示了一些不同的图表。这些不是静态图表,而是根据您可以通过某些按钮等设置的某些过滤器动态生成的。

下一步,我现在正在做的工作是创建一个包含我之前生成的图表的 powerpoint 报告。到目前为止,我得到了这段代码:

report <- pptx(template = 'report_template.pptx')
report <- addSlide(report,"report_layout") 
slide.layouts(report)
slide.layouts(report, "report_layout")
report <- addPlot(report, function() print(p))
writeDoc(report, "example_report.pptx")

以这种方式绘制给定的图表:

p <- plot_ly(agregado_cedex(), labels = ~Escalado, values = ~Total,type = "pie",
          text = ~Total, width = 500, height = 250, hoverinfo = "none") %>% config(displayModeBar = FALSE) %>%
layout(title = "Desglose incidencias", showlegend = TRUE,
       xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
       yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE))

此图表没有问题,因为它正确显示在闪亮的应用程序(仪表板)上。

在执行上面的代码时,我在 R Studio 上遇到了下一个错误:

Warning: Error in .jcall: javax.xml.bind.UnmarshalException
 - with linked exception:
[org.xml.sax.SAXParseException: The markup in the document preceding the root element must be well-formed.]

我发现了一个类似的帖子,但到目前为止还没有解决Add plots in PPTx without crashing R using addplot()

有谁知道怎么回事?提前致谢!

【问题讨论】:

    标签: r powerpoint plotly reporters


    【解决方案1】:

    ReporteRs 不支持 htmlwidgets。 addPlot 使用基本绘图命令、ggplot2、网格和格子。

    【讨论】:

    • 感谢@David Gohel。这是否意味着ReporteRs 不能与plotly 图表一起使用?但是它应该与ggplot2 一起使用,对吧?还有一件事,我是否为函数addPlot 使用了正确的sintax??因为我看过一些使用这种方式的文档:report &lt;- addPlot(report, function(print), x=p ) 或类似的东西
    • @LuisCano 图表是 htmlwidgets,而不是图形设备(arg,它很复杂......)。是的
    • 好的,我现在知道了...但是,我也尝试了一些 ggplot2 图表,但无法正常工作。该图表的代码如下所示:p7 &lt;- ggplot2(some stuff inside this)。此图表位于 render plot 函数内,并且正确显示在我闪亮的应用程序中。然后我尝试将其添加到 PPTX 文件中:report &lt;- addPlot(report, function() print(p7))。我收到此错误Warning: Error in print: object 'p7' not found。如您所见,我不是 R 专家...您知道@DavidGohel 可能出了什么问题吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-09-10
    • 1970-01-01
    • 1970-01-01
    • 2017-07-28
    • 2020-06-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多