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)
When implementing
plotlyOutputinside arenderUIenviroment 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 followingplot-containerandsvg-containerhaven't and so the resulting plot.I'm using the current
shiny(1.3.2) andplotly(4.9.0) version.See this example: