Skip to content

Brushing includes NA valued rows #596

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

Closed
McClellandLegge opened this issue May 23, 2016 · 1 comment
Closed

Brushing includes NA valued rows #596

McClellandLegge opened this issue May 23, 2016 · 1 comment

Comments

@McClellandLegge
Copy link
Contributor

Rows that have NA values for plotting variables are excluded from the plot but are returned by event_data with spurious x and y coordinates with brushing.

plotly_nulls

library(shiny)
library(plotly)


adds <- mtcars[1:5, ]
adds[, c(1, 6)] <- NA
rownames(adds) <- paste(rownames(adds), "(NA)")
some_null_cars <- rbind(mtcars, adds)

ui <- fluidPage(
  radioButtons("plotType", "Plot Type:", choices = c("ggplotly", "plotly")),
  plotlyOutput("plot"),
  verbatimTextOutput("brush")
)

server <- function(input, output, session) {

  output$plot <- renderPlotly({
    # use the key aesthetic/argument to help uniquely identify selected observations
    key <- row.names(some_null_cars)
    if (identical(input$plotType, "ggplotly")) {
      p <- ggplot(some_null_cars, aes(x = mpg, y = wt, colour = factor(vs), key = key)) + 
        geom_point()
      ggplotly(p) %>% layout(dragmode = "select")
    } else {
      plot_ly(some_null_cars, x = mpg, y = wt, key = key, mode = "markers") %>%
        layout(dragmode = "select")
    }
  })

  output$brush <- renderPrint({
    d <- event_data("plotly_selected")
    if (is.null(d)) "Click and drag events (i.e., select/lasso) appear here (double-click to clear)" else d
  })
}

shinyApp(ui, server, options = list(display.mode = "showcase"))


> devtools::session_info()
Session info ----------------------------------------------------------------------------------------------------------------
  setting  value                       
version  R version 3.2.5 (2016-04-14)
system   x86_64, mingw32             
ui       RStudio (0.99.879)          
language (EN)                        
collate  English_United States.1252  
tz       America/Chicago             
date     2016-05-23                  

Packages --------------------------------------------------------------------------------------------------------------------
  package       * version date       source        
assertthat      0.1     2013-12-06 CRAN (R 3.2.5)
base64enc       0.1-3   2015-07-28 CRAN (R 3.2.3)
chron           2.3-47  2015-06-24 CRAN (R 3.2.5)
colorspace      1.2-6   2015-03-11 CRAN (R 3.2.5)
data.table    * 1.9.6   2015-09-19 CRAN (R 3.2.5)
DBI             0.4-1   2016-05-08 CRAN (R 3.2.5)
devtools      * 1.10.0  2016-01-23 CRAN (R 3.2.4)
digest          0.6.9   2016-01-08 CRAN (R 3.2.5)
dplyr           0.4.3   2015-09-01 CRAN (R 3.2.5)
DT            * 0.1     2015-06-09 CRAN (R 3.2.5)
ggplot2       * 2.1.0   2016-03-01 CRAN (R 3.2.5)
gridExtra       2.2.1   2016-02-29 CRAN (R 3.2.5)
gtable          0.2.0   2016-02-26 CRAN (R 3.2.5)
htmltools       0.3.5   2016-03-21 CRAN (R 3.2.5)
htmlwidgets     0.6     2016-02-25 CRAN (R 3.2.5)
httpuv          1.3.3   2015-08-04 CRAN (R 3.2.5)
httr            1.1.0   2016-01-28 CRAN (R 3.2.5)
jsonlite        0.9.20  2016-05-10 CRAN (R 3.2.5)
labeling        0.3     2014-08-23 CRAN (R 3.2.3)
magrittr        1.5     2014-11-22 CRAN (R 3.2.5)
memoise         0.2.1   2014-04-22 CRAN (R 3.2.2)
mime            0.4     2015-09-03 CRAN (R 3.2.3)
munsell         0.4.3   2016-02-13 CRAN (R 3.2.5)
packrat         0.4.6-1 2015-11-05 CRAN (R 3.2.5)
plotly        * 3.6.0   2016-05-18 CRAN (R 3.2.5)
plyr            1.8.3   2015-06-12 CRAN (R 3.2.5)
R6              2.1.2   2016-01-26 CRAN (R 3.2.5)
Rcpp            0.12.5  2016-05-14 CRAN (R 3.2.5)
reshape2      * 1.4.1   2014-12-06 CRAN (R 3.2.5)
rJava           0.9-8   2016-01-07 CRAN (R 3.2.3)
scales          0.4.0   2016-02-26 CRAN (R 3.2.5)
shiny         * 0.13.2  2016-03-28 CRAN (R 3.2.5)
stringi         1.0-1   2015-10-22 CRAN (R 3.2.3)
stringr         1.0.0   2015-04-30 CRAN (R 3.2.5)
tidyr           0.4.1   2016-02-05 CRAN (R 3.2.5)
viridis         0.3.4   2016-03-12 CRAN (R 3.2.5)
XLConnect     * 0.2-11  2015-03-01 CRAN (R 3.2.5)
XLConnectJars * 0.2-9   2014-08-14 CRAN (R 3.2.3)
xtable          1.8-0   2015-11-02 CRAN (R 3.2.5)
yaml            2.1.13  2014-06-12 CRAN (R 3.2.5)
@cpsievert
Copy link
Collaborator

This doesn't appear to be an issue anymore

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

2 participants