If I set the height and the weight to some fixed numbers the size of the plot won't be flexible and won't adjust to the container (a tab panel in my case).
I'm hopeful this example will get you closer to a solution.
I think the missing piece is some javascript that will listen to changes in perhaps the plot width, that you could then force the height for, (in place of my example slider inputs)
library(plotly)
library(shiny)
ui <- fluidPage(
sliderInput("plot_width", "Width", min = 100, max = 1000, step = 10, value = 400),
sliderInput("plot_height", "Height", min = 100, max = 1000, step = 10, value = 400),
plotlyOutput("myplot", width = "400px", height = "400px")
)
server <- function(input, output, session) {
observeEvent(input$plot_height, {
plotlyProxy("myplot", session) %>%
plotlyProxyInvoke("relayout", list(
width = input$plot_height,
height = input$plot_height
))
})
observeEvent(input$plot_width, {
updateSliderInput(
session = session,
"plot_height",
value = input$plot_width
)
})
observeEvent(input$plot_height, {
updateSliderInput(
session = session,
"plot_width",
value = input$plot_height
)
})
output$myplot <- renderPlotly(plot_ly(economics, x = ~date, y = ~uempmed))
}
shinyApp(ui, server)
That's a really cool demonstration but unfortunately it's not very helpful to me. I agree with you about the missing piece, if I'll find something here I'll let you know.