Closed
Description
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)