If I replicate this example of R Shiny app on my computer - full code and data here - the image generated by Shiny has significant white margins that end up cutting some of the words.
Here is an example of the image generated:
Notice that the white space is included in the actual png file generated by shiny, not from white space around the image. The example functions correctly when I see it online from the rstudio servers.
Possible hint: if I increase the resolution (e.g. by setting res = 150
in renderPlot), this white margin increases further. See output image:
How can I remove this white space completely?
Edit: by increasing canvas size (width and height in plotOutput
), and keeping the same resolution in renderPlot
(or by reducing the resolution there), you are less likely to encounter the problem. But the white margin is still there. I want to remove completely the white margin generated by the plot, as in my real life case I have more complex wordclouds, comparison.cloud
, etc.
You can escape this problem by defining the plot size in pixels.
In the demo code this way:
# Show Word Cloud
mainPanel(
plotOutput("plot",width = "500px", height="500px")
)
I eventually managed to deal with it by adding par(mar = rep(0, 4))
before each call to wordcloud
in the server.R file. I don't know if this leads to potential other issues, but for the moment it seems to answer my own question (it removes the white margins from wordclouds in shiny).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With