在 r shiny 中更改 plotly 下载图的尺寸

Changing Dimensions of downloaded plot of plotly in r shiny

我有一个代码,每次都以相同的尺寸下载图形的 png 图像。我想在其中生成质量更高的图像。就像我点击绘图右上角提供的按钮一样,它应该以不同的尺寸下载

参考代码如下

library(shiny)
library(plotly)

ui <- fluidPage(
  selectInput("choice", "Choose", choices = names(iris), selected = NULL),
  plotlyOutput("graph")
  )

server <- function(input, output, session){

  output$graph <- renderPlotly({
    plot_ly(iris, x = ~get(input$choice), y = ~Sepal.Length, type = 'scatter', mode = 'markers')
  })
}

shinyApp(ui, server)

您可以在config函数中使用toImageButtonOptions来设置维度:

plot_ly(
  iris, x = ~get(input$choice), y = ~Sepal.Length, type = 'scatter', mode = 'markers'
) %>% config(
  toImageButtonOptions = list(format = "png", width = 1500, height = 750)
)