Skip to content

Resize behaviour in combination with renderUI() #1553

Description

@Fideldue

When implementing plotlyOutput inside a renderUI enviroment the plots are not resizing properly when changing the size of the container indirectly via an input. The first change works, but if I change back the outer container of the second plot has the right size, but the following plot-container and svg-container haven't and so the resulting plot.
I'm using the current shiny (1.3.2) and plotly (4.9.0) version.

See this example:

library(shiny)
library(plotly)

ui <- fluidPage(
  uiOutput("plotly_outputs"),
  radioButtons("switch", "switch", choices = c("horiz", "vert"), selected = "horiz")
)

server <- function(input, output) {
  
  output$plotly_outputs <- renderUI({
    
    if (input$switch == "horiz"){
      ret <- tagList(
        fluidRow(
          column(width = 6, style = "height:450px",
                 plotlyOutput('plotly_blocks', width = '100%', height = '100%')),
          column(width = 6, style = "height:450px",
                 plotlyOutput('plotly_blocks2', width = '100%', height = '100%'))
        )
      )
    } else {
      tagList(
        fluidRow(
          column(width = 12, style = "height:225px",
                 plotlyOutput('plotly_blocks', width = '100%', height = '100%'))),
        fluidRow(
          column(width = 12, style = "height:225px",
                 plotlyOutput('plotly_blocks2', width = '100%', height = '100%')))
      )
    }
  })
  
  output$plotly_blocks <- renderPlotly({
    input$switch
    calc_plot()
  })
  
  output$plotly_blocks2 <- renderPlotly({
    input$switch
    calc_plot()
  })
  
  calc_plot <- reactive({
    input$switch
    
    plot_ly(economics, x = ~date, color = I("black")) %>%
      add_lines(y = ~uempmed) %>%
      add_lines(y = ~psavert, color = I("red"))
  })

}

shinyApp(ui, server)

Activity

  1. added 2 commits that reference this issue on Jul 12, 2019
    51de36c
    e5ad4a3
  2. added a commit that references this issue on Aug 28, 2019
    e07f80c
  3. jcheng5 commented on Aug 30, 2019

    @jcheng5
    Contributor

    @cpsievert and I found that renaming plotly_blocks/plotly_blocks2 to plot0/plot1 fixes it!? #1575 is a sane fix but we should figure out what this mystery is too.

  4. added a commit that references this issue on Mar 12, 2020
    32dde41
  5. added a commit that references this issue on Jun 26, 2022
    504c33f
  6. added a commit that references this issue on Jul 4, 2022
    55f49ee
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions