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)