plotly / plotly/plotly.R

plotly plot rendering squished when switching tabs quickly in shinydashboard

Open
#1,784 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
R
Stars
2.7k
Forks
641
PR merge metrics
No merged PRs in 30d

Description


There seems to be an issue rendering the plots reliably when moving between tabs quickly on shinydashboard. Specifically, the plotlyOutput seems to get squished into a very thin plot when you switch away from the tab that it is on before it's rendered, and then switch back.

I found two other questions on Stack Overflow from people experiencing the same issue; one of these questions had a answer with a hacky workaround answer that I'm currently using to solve the problem. I'm including the reprex from their question (I hope the OP of the Stack Overflow question doesn't take issue with that). I've also included links to the Stack Overflow questions.

https://stackoverflow.com/questions/44587825/plotly-chart-not-rendering-correctly-in-shiny-dashboard

https://stackoverflow.com/questions/52973305/shiny-plotly-plot-stuck-when-switching-tabs-quickly
(this is the one with the reprex and the hacky solution)

For now, the hacky solution provided works alright enough for my purposes, but it's still a little bit ugly and it would be nice to have this solved more robustly.

time_waste<- function(magnitude) {
  y<-0
  for(i in 1:magnitude) {
    y<- y + rnorm(1,0,1)
  }
  return(abs(y))
}

ui <- fluidPage(sidebarLayout(
    sidebarPanel(width = 3,
                              fluidRow(
                                column(
                                  4,
                                  numericInput(
                                    inputId = "magnitude",
                                    label = "magnitude",
                                    value = 1000000
                                      )))),
    mainPanel(width = 8,
              tabsetPanel(id = "tabset",
                          tabPanel("Plot1", plotlyOutput("p1", height = "700px")),
                          tabPanel("Plot2", plotlyOutput("p2", height = "700px"))))
  )
  )

server<- function(input, output, session) {

  y<- reactive({
    rep(time_waste(time_waste(input$magnitude)),3)
  })

  output$p1 <- renderPlotly({

  p<- plot_ly(
    x = c("giraffes", "orangutans", "monkeys"),
    y = y(),
    name = "SF Zoo",
    type = "bar"
  )
  })

  output$p2<-  renderPlotly({

    p<- plot_ly(
      x = c("giraffes", "orangutans", "monkeys"),
      y = y(),
      name = "SF Zoo",
      type = "bar"
    )

  return(p)
  })

}

app <- shinyApp(ui, server)
runApp(app)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the provided Shiny reprex with its plotlyOutput and renderPlotly calls, then reproduce switching tabs before the plots render. Compare the behavior with the two linked Stack Overflow reports; done means plots retain their intended size after rapid tab switching without the current workaround.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
data-visualization, frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.