🚀 Gen 5 of the leading AI app deployment platform launches October 6. Click for the livestream.

Plotly + Shiny Dashboard - Plot Margin Issue

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():

I am having the same issue!

This should be fixed in the latest dev version of plotly

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

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?

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

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.

Attachment 2

This issue had resolved itself (can’t remember how) until today. I just updated my plotly package to 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.

1 Like

After downgrading back to plotly version 4.6.0…the issue is no longer present.
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?

1 Like

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.


I was wondering if there were any news on the topic.

We use plotly with an R markdown document that uses flexdashboard and shinydashboard and I constantly experience the issue described above. I also should not hardcode the dimensions as all of our content is “flex” and adjusts in size as needed to fill the page.

Sometimes, if I zoom out and back into the page of the web browser (CTRL + -/+), the issue disappears. But often, the plot has to become tiny before it is displayed fully and upon zooming in, half of it disappears again. My problems mainly concern the y axis, because the plots seem to be too wide.

Any ideas?