Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with plotlyOutput width argument #1036

Closed
vnijs opened this issue May 31, 2017 · 16 comments
Closed

Issue with plotlyOutput width argument #1036

vnijs opened this issue May 31, 2017 · 16 comments

Comments

@vnijs
Copy link

vnijs commented May 31, 2017

Same install with 4.6.0 the width arguments works fine. After upgrading to 4.7.0 the default width is very narrow and changing the width setting has no effect in the browser. After reinstalling 4.6.0 the width argument works fine again. Any ideas?

library(shiny)
library(plotly)

## Define UI for application 
ui <- fluidPage(
  titlePanel("My Shiny app with plotly"),
  sidebarLayout(
    sidebarPanel(
      sliderInput("my_slider", label = "Number of data points", 
                  min = 100, max = 500, value = 200)
    ),
    mainPanel(
      plotlyOutput("show_scatter", width = "100%")
    )
  )
)

# Define server logic 
server <- function(input, output) {
  output$show_scatter <- renderPlotly({
    y <- rnorm(input$my_slider)
    x <- y  + rnorm(input$my_slider)
    df <- data.frame(x = x, y = y)
    p <- ggplot(df, aes(x = x, y = y)) + 
      geom_point()
    ggplotly(p)
  })
}

# Run the application with plotly
shinyApp(ui = ui, server = server)
@vnijs
Copy link
Author

vnijs commented May 31, 2017

Adding screenshots for 4.6 and 4.7.

In 4.6.0:

4 6

In 4.7.0:

4 7

@vnijs
Copy link
Author

vnijs commented May 31, 2017

Just noticed something interesting ... as I change the size of the viewer panel in Rstudio, the size of the plot changes in the browser (after refresh).

@cpsievert
Copy link
Collaborator

cpsievert commented May 31, 2017

I'm not sure specifying height/width in plotlyOutput() has ever really worked the way you'd expect it to in all situations/contexts.

For now, you can specify height/width in ggplotly() or plot_ly(), but I'll think about a better long-term solution

@vnijs
Copy link
Author

vnijs commented May 31, 2017

OK. But autosizing worked when no width was set in 4.6.0 and no longer does that at all in 4.7.0. In fact, the size of the image in a Shiny app shown in Chrome seems to be determined by the size of the Viewer panel in Rstudio. Adding another set of screenshots below as illustration.

4.7.0

screen shot 2017-05-31 at 4 16 31 pm

4.6.0

screen shot 2017-05-31 at 4 19 27 pm

@cpsievert
Copy link
Collaborator

Ok, yea, that's definitely a problem. Does the same thing happen if you launch the app outside of RStudio?

@cpsievert
Copy link
Collaborator

Also, BTW, an official fix for this may take a bit, but for now, if you want the old behavior back:

l <- ggplotly(qplot(1:10))
l$x$layout$width <- NULL
l$x$layout$height <- NULL
l$width <- NULL
l$height <- NULL
l

@vnijs
Copy link
Author

vnijs commented Jun 1, 2017

The issue doesn't seems to occur outside of Rstudio. The fix does seems to work from Rstudio.

@vnijs
Copy link
Author

vnijs commented Jun 1, 2017

Works! Thanks @cpsievert

@peranti
Copy link

peranti commented Jun 7, 2017

@cpsievert The fix works for dynamically adjusting the plotly output wrt width. However, the height of the plot is not dynamically adjusting to the browser window.

@daattali
Copy link

It seems width+height in plotlyOutput() still don't work (in a browser), but setting it in ggplotly() does. If they aren't intended to work in plotlyOutput(), would it be a good idea to remove them from the signature, or at least mention in the documentation that they don't work?

@cpsievert
Copy link
Collaborator

Could you be more specific by "doesn't work"? Both height/width seem to work for me.

@daattali
Copy link

the height and width arguments seem to be completely ignored when used in plotlyOutput in a shiny app

> packageVersion("shiny")
[1] ‘1.0.5’
> packageVersion("htmlwidgets")
[1] ‘0.9’
> packageVersion("plotly")
[1] ‘4.7.0’

Actually, after doing a specific small code example I think that the container is set to the proper dimensions, but the plot isn't. Example:

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

ui <- fluidPage(
  plotlyOutput("p1", height=100, width=100),
  plotlyOutput("p2")
)

server <- function(input, output, session) {
  output$p1 <- renderPlotly({
    ggplotly(ggplot(mtcars, aes(mpg,wt))+geom_point())
  })
  output$p2 <- renderPlotly({
    ggplotly(ggplot(mtcars, aes(mpg,wt))+geom_point(), width=100,height=100)
  })
}

shinyApp(ui, server)

Result:

image

Notice that the small plot (which is p2) looks like it's starting 100px down, meaning the p1 actually does think it's only 100px tall, but the plot itself is regular sized. Hope that makes sense

@cpsievert
Copy link
Collaborator

Changes have been made here since 4.7.0 -- 7a8ee9c

Can you please try with a more recent version?

@daattali
Copy link

Ah yes the dev version works! The bug report title is for v 4.7.0 so I thought that was the latest

@cpsievert cpsievert changed the title plotlyOutput width argument no longer works in 4.7.0 Issue with plotlyOutput width argument Sep 11, 2017
@dfrail24
Copy link

dfrail24 commented Apr 3, 2018

I was seeing this issue with the newest dev version - reverting back to 4.7.1 version on CRAN did fix the issue though.

@cosmin-novac
Copy link

Still seeing this issue in 4.9.0 when using plotlyOutput inside renderUI.

Setting the plotlyOutput width to "auto" results in a plot that is too small width-wise, and setting the width to NULL removes the height style attribute alltogether. Setting the width to 100% doesn't work at all, the app just crashes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants