在闪亮的应用程序上,ggplotly()呈现plot_ly()大小的一半.如何解决? [英] On shiny app ggplotly() renders half the size of plot_ly(). How to fix that?
本文介绍了在闪亮的应用程序上,ggplotly()呈现plot_ly()大小的一半.如何解决?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当使用ggplotly vs plot_ly在闪亮的应用程序中生成绘图时,绘图的宽度小于一半.这是为什么?有没有一种方法可以修复它,以便ggplotly生成与plot_ly或ggplot2相同宽度的图?我尝试使用width参数,但这不能解决问题.
A plot's width is less than half when using ggplotly vs plot_ly to generate a plotly in a shiny app. Why is that? Is there a way to fix it so that ggplotly produces the plot with the same width as plot_ly or ggplot2? I have tried using the width parameter but that doesn't fix it.
闪亮应用程序的输出:
Output from the shiny app:
library(shiny)
library(plotly)
library(ggplot2)
ui <- fluidPage(
titlePanel("plotly with shiny"),
mainPanel(
h4("Using ggplotly:"), plotlyOutput("ggplotly", width = "200"),
h4("Using native plotly:"), plotlyOutput("plotly"),
h4("Using ggplot:"), plotOutput("ggplot")
)
)
server <- function(input, output) {
data <- reactive({
d = diamonds[sample(nrow(diamonds), 300),]
})
output$ggplot <- renderPlot({
ggplot(data(), aes(x=carat, y=price, color=price)) + geom_point()
})
output$ggplotly <- renderPlotly({
v = ggplot(data(), aes(x=carat, y=price, color=price)) + geom_point()
ggplotly(v)
})
output$plotly <- renderPlotly({
plot_ly(data(), x = ~carat, y = ~price, color = ~price)
})
}
shinyApp(ui = ui, server = server)
推荐答案
请勿使用plotlyOutput
的自变量width
,而应使用ggplotly
的自变量:
Do not use the argument width
of plotlyOutput
, and use the one of ggplotly
:
ggplotly(v, width=800)
这篇关于在闪亮的应用程序上,ggplotly()呈现plot_ly()大小的一半.如何解决?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文