[英]On shiny app ggplotly() renders half the size of plot_ly(). How to fix that?
A plot's width is less than half when using ggplotly vs plot_ly to generate a plotly in a shiny app. 当使用ggplotly vs plot_ly在闪亮的应用程序中生成情节时,绘图的宽度小于一半。 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?
有没有办法解决它,以便ggplotly生成与plot_ly或ggplot2相同宽度的图? I have tried using the width parameter but that doesn't fix it.
我尝试过使用width参数,但是没有修复它。
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
的一个:
ggplotly(v, width=800)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.