inst/examples/shiny/ggplotly_sizing/app.R

library(shiny)
library(plotly)

ui <- fluidPage(
  plotlyOutput("pid")
)

server <- function(input, output, session, ...) {
  
  # to relay the height/width of the plot's container, we'll query this 
  # session's client data http://shiny.rstudio.com/articles/client-data.html
  cdata <- session$clientData
  
  output$pid <- renderPlotly({
    p <- ggplot(iris) + 
      geom_point(aes(Sepal.Length, Sepal.Width)) +
      facet_wrap(~Species)
    
    ggplotly(p, width = cdata$output_pid_width, height = cdata$output_pid_height)
  })
  
}

shinyApp(ui, server)

Try the plotly package in your browser

Any scripts or data that you put into this service are public.

plotly documentation built on Nov. 10, 2022, 5:42 p.m.