On a shiny app, ggplotly () renders half the size of plot_ly (). How to fix it?
The plot width is less than half when using ggplotly vs plot_ly to create a plot in a shiny application. Why is this? Is there a way to fix this so that ggplotly generates a plot with the same width as plot_ly or ggplot2? I tried using the width parameter, but that doesn't fix it.
Exiting 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)
+3
source to share