有条不紊的plotlyOutput()没有响应高度和宽度大小

4 r shiny plotly

我正在创建一个带有绘图散点图的Shiny应用程序.我试图保持散点图方形,但想要比默认大得多的尺寸.例如,在下面的简单MWE中,我将宽度和高度参数设置为1400px.但是,即使我更改这些值(比如800px),它似乎也没有对绘图散点图的大小做任何改变.

library(plotly)
library(shiny)
library(ggplot2)

set.seed(1)
dat <- data.frame(ID = paste0("ID", 1:100), x = rnorm(100), y = rnorm(100), stringsAsFactors = FALSE)

ui <- shinyUI(fluidPage(
  titlePanel("title panel"),
  sidebarLayout(position = "left",
  sidebarPanel(width=3,
    actionButton("goButton", "Action")
   ),
  mainPanel(width=9, 
    plotlyOutput("scatMatPlot", width = "1400px", height = "1400px")
  )
  )
))

server <- shinyServer(function(input, output, session) {
  p <- ggplot(data= dat, aes(x=x, y=y)) + geom_point() + coord_cartesian(xlim = c(-5, 5), ylim = c(-5, 5)) + coord_equal(ratio = 1) 
  p2 <- ggplotly(p)
  output$scatMatPlot <- renderPlotly({p2})
})

shinyApp(ui, server)
Run Code Online (Sandbox Code Playgroud)

我尝试了其他尺寸值而不是"1400px".例如,我试过"自动"和"100%" - 但这些似乎也没有什么区别.如何更改此MWE中的绘图散点图的大小?谢谢你的任何意见.

Dia*_*Log 8

使用时,ggplotly()您可以使用plotlyOutput服务器部件中的布局选项更改大小:

p2 <- ggplotly(p) %>% layout(height = 800, width = 800)
Run Code Online (Sandbox Code Playgroud)

我发现, plotlyOutput将只与参数的工作width = "600px", height = "600px",如果你直接从提供输入plot_ly()代替ggplotly(),如

p2 <- plot_ly(dat, x = ~x, y = ~y)
Run Code Online (Sandbox Code Playgroud)