Reduce/remove 在 Shiny 应用程序中绘制边距,包括 wordclouds

Reduce/remove plot margins in Shiny apps including wordclouds

如果我复制 this example of R Shiny app on my computer - full code and data here - Shiny 生成的图像有明显的白边,最终会剪掉一些文字。

这是生成的图像示例:

请注意,白色 space 包含在 shiny 生成的实际 png 文件中,而不是图像周围的白色 space。当我看到该示例时,该示例运行正常 online from the rstudio servers

可能的提示:如果我增加分辨率(例如通过在 renderPlot 中设置 res = 150),这个白边会进一步增加。查看输出图像:

如何彻底去除这个白色 space?

编辑:通过增加 canvas 大小(plotOutput 中的宽度和高度),并在 renderPlot 中保持相同的分辨率(或降低那里的分辨率),你可以减少可能会遇到问题。但是白边仍然存在。我想完全去除情节产生的白边,因为在我的现实生活中,我有更复杂的词云,comparison.cloud,等等。

您可以通过以像素为单位定义绘图大小来避免此问题。

在演示代码中是这样的:

# Show Word Cloud
mainPanel(
  plotOutput("plot",width = "500px", height="500px")
)

我最终设法通过在 server.R 文件中每次调用 wordcloud 之前添加 par(mar = rep(0, 4)) 来处理它。我不知道这是否会导致其他潜在问题,但目前它似乎回答了我自己的问题(它从闪亮的字云中删除了白边)。