plotly / plotly.R

An interactive graphing library for R
https://plotly-r.com
Other
2.54k stars 622 forks source link

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

Open RoelVerbelen opened 4 years ago

RoelVerbelen commented 4 years ago

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)
AnthisKon commented 1 year ago

Facing the same issue, any workaround available?