Skip to content

Shiny plotly sizing issue for plotlyOutput() when width = 100% #1827

@RoelVerbelen

Description

@RoelVerbelen

When using the default width = 100% for plotlyOutput() in Shiny apps, I always run into issues where the width doesn't scale to the full width when clicking away before the plot is fully rendered. When clicking back, the plot's width doesn't adjust or rescale. This setting occurs often in practice when designing a shinydashboard with multiple tabItems(). Minimal example and a GIF to better explain what I mean below. Posting it here, but please advise if this should be an htmlwidgets or shiny issue instead.

plotlyOutput

library(shiny)
library(plotly)

ui <- navbarPage(
  title = "Minimal Example",
  tabPanel("Home", HTML("Click the `Plot` tab and then rapidly back on the `Home` tab. Wait 2 seconds and then click the `Plot` tab again.")),
  tabPanel("Plot", plotlyOutput("plot"))
)

server <- function(input, output) {
  output$plot <- renderPlotly({
    Sys.sleep(2)
    plot_ly(iris, x = ~Sepal.Width, y = ~Sepal.Length, type = "scatter", mode = "markers")
  })
}

shinyApp(ui, server)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions