Closed
Description
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, and link to 2ndary boxplot.
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 - the lower window updates the event information in scatter3d but not for 2d. The boxplots link in 3d but not 2d:
# Dummy data
pathotype.z <- data.frame(x=rnorm(15000), y=rnorm(15000), logP=rnorm(15000)^2, hcol=sample(1:5, 15000, replace=T),
gene=paste0("A", as.integer(rnorm(15000)*10000)))
genelookup <- list()
genelookup <- tapply(pathotype.z$gene, pathotype.z$hcol, function(x) x)
ui <- fluidPage(fluidRow(column(8, plotlyOutput("volc3d", height=640)),
column(4, plotlyOutput("scatterplot", height=500),
fluidRow(
column(12, radioButtons("plottype", label = h5("Plot"),
choices = list("2d" = 1, "3d" = 2), selected = 2))
))),
verbatimTextOutput("selection"))
server <- function(input, output, session) {
output$volc3d <- renderPlotly({
pt <- as.numeric(input$plottype)
if (length(pt)==0) pt <- 2
if (pt==2) {
plot_ly(d=pathotype.z, x=~x, y=~y, z=~logP,
marker=list(size=2.5), color=~hcol,
text=~gene, type='scatter3d', mode = 'markers', source='volc3d')
} else {
plot_ly(data=pathotype.z, x=~x, y=~y,
marker=list(size=5), color=~hcol,
text=~gene, type="scattergl", mode = "markers")
}})
output$selection <- renderPrint({
s <- event_data("plotly_click", source = "volc3d")
if (length(s) == 0) {"Click on gene to display scatterplot"
} else {
as.list(s)
}})
output$scatterplot <- renderPlotly({
s <- event_data("plotly_click", source = "volc3d")
if (length(s)) {
p <- s[["pointNumber"]]
c <- s[["curveNumber"]]
gene <- genelookup[[c+1]][p+1]
plot_ly(pathotype.z, x=~hcol, y=~y, type='box') %>%
layout(title=gene, yaxis=list(title=gene),
margin=list(t=100,l=50,r=50,b=50))
} else {plotly_empty()}
})
}
shinyApp(ui, server)
Here is session info:
> sessionInfo()
R version 3.3.1 (2016-06-21)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
locale:
[1] LC_COLLATE=English_United Kingdom.1252 LC_CTYPE=English_United Kingdom.1252 LC_MONETARY=English_United Kingdom.1252
[4] LC_NUMERIC=C LC_TIME=English_United Kingdom.1252
attached base packages:
[1] grid parallel stats4 stats graphics grDevices utils datasets methods base
other attached packages:
[1] gplots_3.0.1 ComplexHeatmap_1.10.2 ggforce_0.1.1 shiny_0.14.2
[5] plotly_4.5.6 ggplot2_2.2.0 DESeq2_1.12.4 SummarizedExperiment_1.2.3
[9] Biobase_2.32.0 GenomicRanges_1.24.3 GenomeInfoDb_1.8.7 IRanges_2.6.1
[13] S4Vectors_0.10.3 BiocGenerics_0.18.0
loaded via a namespace (and not attached):
[1] bitops_1.0-6 RColorBrewer_1.1-2 httr_1.2.1 prabclus_2.2-6 tools_3.3.1 R6_2.2.0
[7] KernSmooth_2.23-15 rpart_4.1-10 Hmisc_4.0-1 DBI_0.5-1 lazyeval_0.2.0 colorspace_1.3-2
[13] trimcluster_0.1-2 nnet_7.3-12 GetoptLong_0.1.5 gridExtra_2.2.1 base64_2.0 htmlTable_1.7
[19] labeling_0.3 caTools_1.17.1 diptest_0.75-7 scales_0.4.1 DEoptimR_1.0-8 mvtnorm_1.0-5
[25] robustbase_0.92-7 genefilter_1.54.2 stringr_1.1.0 digest_0.6.10 foreign_0.8-67 XVector_0.12.1
[31] base64enc_0.1-3 htmltools_0.3.5 htmlwidgets_0.8 GlobalOptions_0.0.10 RSQLite_1.1-1 shape_1.4.2
[37] jsonlite_1.1 mclust_5.2 BiocParallel_1.6.6 gtools_3.5.0 acepack_1.4.1 dendextend_1.3.0
[43] dplyr_0.5.0 RCurl_1.95-4.8 magrittr_1.5 modeltools_0.2-21 Formula_1.2-1 Matrix_1.2-7.1
[49] Rcpp_0.12.8 munsell_0.4.3 yaml_2.1.14 stringi_1.1.2 whisker_0.3-2 MASS_7.3-45
[55] zlibbioc_1.18.0 flexmix_2.3-13 plyr_1.8.4 gdata_2.17.0 udunits2_0.13 lattice_0.20-33
[61] splines_3.3.1 annotate_1.50.1 circlize_0.3.9 locfit_1.5-9.1 knitr_1.15.1 rjson_0.2.15
[67] fpc_2.1-10 geneplotter_1.50.0 XML_3.98-1.5 latticeExtra_0.6-28 data.table_1.10.0 tweenr_0.1.5
[73] httpuv_1.3.3 gtable_0.2.0 openssl_0.9.5 purrr_0.2.2 tidyr_0.6.0 kernlab_0.9-25
[79] assertthat_0.1 mime_0.5 xtable_1.8-2 class_7.3-14 survival_2.39-4 viridisLite_0.1.3
[85] tibble_1.2 AnnotationDbi_1.34.4 memoise_1.0.0 units_0.4-1 cluster_2.0.5