Resizing shiny-plotly output height and width automatically based on window

I would like to have the shiny-plotly output height and width adjusted to the current window size. I have tried to use the below but of no use.

ShinyUi ← fluidPage(

Application title

titlePanel(“title”),

sidebarLayout(
sidebarPanel(
… inputs …
),

mainPanel(
      plotlyOutput("distPlot", height = 'auto', width = 'auto')
  )

))

ShinyServer ← function(input, output, session) {

output$distPlot ← renderPlotly({

p <- ggplot(dataShow, aes(x=dataShow$X, y=dataShow$Y))  + 

geom_point(shape=1, alpha = 0.5, color = “grey50”)

ggplotly(p)

})

}

shinyApp(ui = ShinyUi, server = ShinyServer)

Would you know of any other options to use maybe in server function instead of the above UI function usage?

1 Like

Hello~. This is the best I found on the topic, and probably close to the best available. I might mess with the javascript a little, and your Shiny code setup is probably different than in this post. Mine was too, but I got it to work for me: r - dynamically adjust height and/or width of shiny-plotly output based on window size - Stack Overflow

I left an answer here.