You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
event_data doesn't work with scatterplot (type = "scattergl") #624
Everything works fine until I changed the type = 'scatter' to type = 'scattergl'
I lost the "box select" option after the change.
In comparison, it work fine for ggplot + ggplotly and I can still get the data info from the selected box area.
I would like to use the additional features from plot_ly instead of switching back to ggplot
Thank you for your help.
Here is a minimal example code
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", type = "scattergl") %>%
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)
Here is my session info:
> sessionInfo()
R version 3.3.0 (2016-05-03)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.11.5 (El Capitan)
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] plotly_3.6.4 ggplot2_2.1.0 shiny_0.13.2
loaded via a namespace (and not attached):
[1] Rcpp_0.12.5 magrittr_1.5 munsell_0.4.3 colorspace_1.2-6 xtable_1.8-2
[6] R6_2.1.2 httr_1.1.0 plyr_1.8.3 dplyr_0.4.3 tools_3.3.0
[11] parallel_3.3.0 grid_3.3.0 gtable_0.2.0 DBI_0.4-1 htmltools_0.3.5
[16] yaml_2.1.13 digest_0.6.9 assertthat_0.1 gridExtra_2.2.1 tidyr_0.4.1
[21] base64enc_0.1-3 htmlwidgets_0.6 viridis_0.3.4 rsconnect_0.4.3 mime_0.4
[26] labeling_0.3 scales_0.4.0 jsonlite_0.9.20 httpuv_1.3.3
I know this is supposed to have been fixed in plotly.js but I find that the 2d scatter plot using either type='scattergl' or toWebGL() breaks the plotly_click event in plotly.r. It works fine for me for scatter3d. I want to show a 2d plot of 21,000 points, hence the need for scattergl.
Activity
cpsievert commentedon Jun 8, 2016
Marking this as a duplicate since this is a known limitation of gl2d trace types -- plotly/plotly.js#130
naikai commentedon Jun 9, 2016
Sorry I missed it. Thanks
myles-lewis commentedon Jan 6, 2017
I know this is supposed to have been fixed in plotly.js but I find that the 2d scatter plot using either type='scattergl' or toWebGL() breaks the plotly_click event in plotly.r. It works fine for me for scatter3d. I want to show a 2d plot of 21,000 points, hence the need for scattergl.
This issue was reported here: plotly/plotly.js#743
but is supposed to have been completed here: plotly/plotly.js#994
Here is demo code:
Here is session info: