Plotly + Shiny Dashboard - Plot Margin Issue


#1

I am having an issue with the way a ggplot is rendered via plotly within a fluidrow box inside the Shiny Dashboard app I have created. In the example screen shot below, the x-axis text is missing about 4 characters and the y-axis label is partially rendered.

The outside margins of the plot look to be getting clipped and do not render the text completely for both the x & y axes. Is there a way to pad the margins of the plot to ensure all text can be made visible? I have tried adding an HTML break() within the plot window using shiny code and it does not resolve the issue. I also don’t see this same issue with any other charting package used for this app. Any help/information is appreciated.

Example w/ HTML break():


#2

I am having the same issue!


#3

This should be fixed in the latest dev version of plotly


#4

You can always add to the margin like this, however:

p <- plot_ly()
l <- plotly_build(p)
l$layout$margin$b <- l$layout$margin$b + 30
l

#5

Thanks Carson.

When will the update be migrated to the official plotly version?
Can you provide some quick instruction on how to source the latest dev build in R?


#6

You can install the dev version with devtools::install_github("ropensci/plotly"). I’ll be submitting to CRAN within the next week


#7

Thanks Carson. I installed the devtools version and am still observing the issue.

The issue seems related to whether or not an axis label is present.

  • When no axis label is present…the text on the x-axis is not displayed entirely and is missing 2-3 characters (see attachment 1).

  • When an axis label is present…the text on the tick marks is displayed entirely but is over the axis label (attachment 2).

The issue also seems isolated to the x-axis. The clipping of the y-axis label (observed in my original post seems to have been resolved. Any additional help with this issue is greatly appreciated.


#8

Attachment 2


#9

This issue had resolved itself (can’t remember how) until today. I just updated my plotly package to 4.7.0.9000 and now the output graphs will not stay within the bounds of a box in my shinydashboard app. Specifying width or height arguments to plotlyOutput do not solve the issue.

Is there a way to force the plot to stay within the bounds of the box again? Any help is appreciated.

box(width = 12, title = tagList(shiny::icon("flask")," Crude Yield:"), status = "primary", solidHeader = TRUE, plotlyOutput("primer_crude_od"))

An example image where it can be seen that the plot ignores both height and width arguments can be found attached.


#10

After downgrading back to plotly version 4.6.0…the issue is no longer present.
require(devtools)
install_version("plotly", version = "4.6.0", repos = "http://cran.us.r-project.org")

Resizing the browser window causes the plot to resize itself and stay within the box margins (as expected). Any idea what changed between versions that may have caused this?


#11

I ran into the same problem today. One workaround I found was applying the width inside my plot function where I call ggplotly:

ggplotly(g, tooltip = c("x", "y"), show.legend = FALSE, height = 250)

But I use the plot in multiple locations with various sizes and I don’t want to have to feed a parameter from server.R into the function. It also doesn’t resolve a similar issue with the width.

Definitely a bug that needs to be fixed.