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

plotOutput UI options don't work with ggplot2 3.0 #2173

Closed
leedrake5 opened this issue Sep 4, 2018 · 5 comments
Closed

plotOutput UI options don't work with ggplot2 3.0 #2173

leedrake5 opened this issue Sep 4, 2018 · 5 comments
Assignees
Labels
Difficulty: Advanced Effort: Low Need Info Additional information has been requested
Milestone

Comments

@leedrake5
Copy link

@leedrake5 leedrake5 commented Sep 4, 2018

With ggplot2 2.2.1, it was straightforward to get interactivity with a plot. nearPoints, brush, plot clicks, and other features worked quite well. With ggplot2 3.0, however, the normal functionality no longer works. There are two manifestations of this so far:

  1. Shiny maps to the number of pixels on the plot, not the plot data. If I have an x and y bivariate plot ranging from 0 to 1, and I interact with the plot (say brush to zoom) in the lower left, the plot won't read 0 on the y axis, but instead will map to its maximum height (if height = 465, then the lowest point on the graph is 465, not 0 as is the case in the original data).
  2. Shiny nearPoints can't automatically fill in xvar and yvar of a ggplot. Earlier, nearPoints could automatically identify xvar and yvar in ggplots. Whatever changed in ggplot2 3.0 also broke this functionality.

If I am missing anything let me know, but it strikes me that the changes to ggplot2 3.0 to align it within the tidyverse have broken the way shiny access its data. This manifests as failing to read xvar and yvar in nearPoints, as well as plot interactivity defaulting to the pixels of the plot instead of its data.

Thanks for building such a fantastic package, I hope these comments are helpful in future updates to shiny.

@jcheng5 jcheng5 added this to the 1.2 milestone Sep 14, 2018
@schloerke
Copy link
Collaborator

@schloerke schloerke commented Sep 17, 2018

@leedrake5 With cran shiny and cran ggplot2 and the example below, I do not observe the behavior. (Inspired and reduced from 105-plot-interaction-zoom)

Do you have a small example app that I could try to reproduce with on my end? Thank you in advance!

-Barret

source("zoom.R")
# zoom.R
install.packages(c("shiny", "ggplot2"))
library(shiny)
library(ggplot2)

ui <- fluidPage(
  fluidRow(
    column(width = 4, class = "well",
      h4("Brush and double-click to zoom"),
      plotOutput("plot1", height = 300,
        dblclick = "plot1_dblclick",
        brush = brushOpts(
          id = "plot1_brush",
          resetOnNew = TRUE
        )
      )
    )
  )
)

server <- function(input, output) {

  # -------------------------------------------------------------------
  # Single zoomable plot (on left)
  ranges <- reactiveValues(x = NULL, y = NULL)
  dt <- data.frame(x = runif(100), y = runif(100))
  output$plot1 <- renderPlot({
    ggplot(dt, aes(x, y)) + geom_point() +
      coord_cartesian(xlim = ranges$x, ylim = ranges$y, expand = FALSE)
  })

  # When a double-click happens, check if there's a brush on the plot.
  # If so, zoom to the brush bounds; if not, reset the zoom.
  observeEvent(input$plot1_dblclick, {
    brush <- input$plot1_brush
    if (!is.null(brush)) {
      ranges$x <- c(brush$xmin, brush$xmax)
      ranges$y <- c(brush$ymin, brush$ymax)

    } else {
      ranges$x <- NULL
      ranges$y <- NULL
    }
  })

}

shinyApp(ui, server)

@schloerke schloerke added Need Info Additional information has been requested Difficulty: Advanced Effort: Low labels Sep 17, 2018
@jcheng5
Copy link
Member

@jcheng5 jcheng5 commented Sep 18, 2018

Hi @leedrake5, sorry to bug you but would it be possible for you to provide a little more information (best of all would be a reproducible example)? We're trying to close out the bug fixing period for Shiny v1.2 this week, and if there's a real issue here we would definitely want to fix it. Also it'd be helpful to know whether you install ggplot2 3.0.0 from CRAN or from GitHub (devtools::session_info() will tell you the exact commit ID in the latter case).

Thanks!

@leedrake5
Copy link
Author

@leedrake5 leedrake5 commented Sep 18, 2018

@jcheng5
Copy link
Member

@jcheng5 jcheng5 commented Sep 19, 2018

Thanks @leedrake5, that would be much appreciated.

@leedrake5
Copy link
Author

@leedrake5 leedrake5 commented Sep 19, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Difficulty: Advanced Effort: Low Need Info Additional information has been requested
Projects
None yet
Development

No branches or pull requests

4 participants