dreamRs / apexcharter

:bar_chart: R Htmlwidget for ApexCharts.js
https://dreamrs.github.io/apexcharter
Other
138 stars 15 forks source link

getSelection() JavaScript function conflicts with rhandsontable #35

Closed merlinoa closed 3 years ago

merlinoa commented 3 years ago

Thanks for all your great open source Shiny work.

When I run the following app (with both apexcharter and rhandsontable) and click on a cell in the handsontable, I get the following JavaScript error.

Uncaught TypeError: Cannot read property 'opts' of undefined
    at getSelection (apexcharter.js:44)
    at d (handsontable.full.min.js:34)
    at HTMLDivElement.<anonymous> (handsontable.full.min.js:34)
    at HTMLDivElement.o (handsontable.full.min.js:29)
library(shiny)
library(rhandsontable)
library(apexcharter)

ui <- fluidPage(
  fluidRow(
    column(
      6,
      rHandsontableOutput("handson_out")
    ),
    column(
      6,
      apexchartOutput("apex_out")
    )
  )
)

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

  output$apex_out <- renderApexchart({
    data("mpg", package = "ggplot2")
    n_manufac <- dplyr::count(mpg, manufacturer)

    apex(data = n_manufac, type = "bar", mapping = aes(x = manufacturer, y = n))
  })

  output$handson_out <- renderRHandsontable({

    rhandsontable(
      iris
    )
  })
}

shinyApp(ui, server)

It looks like this is a namespace issue between your getSelection() function here: https://github.com/dreamRs/apexcharter/blob/5560ae0b31d2a64785404daa9bc225198f15c898/inst/htmlwidgets/apexcharter.js#L42 and a function also called getSelection that jqueryUI attaches to the window object.

Here is my session info:

R version 4.0.3 (2020-10-10)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Catalina 10.15.7

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib

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] apexcharter_0.1.6   rhandsontable_0.3.7 shiny_1.5.0        

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.5        compiler_4.0.3    pillar_1.4.6      later_1.1.0.1     tools_4.0.3       packrat_0.5.0    
 [7] digest_0.6.27     jsonlite_1.7.1    lifecycle_0.2.0   tibble_3.0.4      gtable_0.3.0      pkgconfig_2.0.3  
[13] rlang_0.4.8       cli_2.1.0         rstudioapi_0.12   yaml_2.2.1        fastmap_1.0.1     withr_2.3.0      
[19] dplyr_1.0.2       generics_0.1.0    htmlwidgets_1.5.2 vctrs_0.3.4       grid_4.0.3        tidyselect_1.1.0 
[25] glue_1.4.2        R6_2.5.0          fansi_0.4.1       ggplot2_3.3.2     purrr_0.3.4       magrittr_1.5     
[31] scales_1.1.1      promises_1.1.1    htmltools_0.5.0   ellipsis_0.3.1    assertthat_0.2.1  mime_0.9         
[37] xtable_1.8-4      colorspace_1.4-1  httpuv_1.5.4      munsell_0.5.0     crayon_1.3.4.9000
> 
pvictor commented 3 years ago

Thanks Andy :) Hope your fine!

Thanks for reporting this, this is fixed. I'll push to CRAN by the end of week, in the meantime you can use GitHub version.

Victor

merlinoa commented 3 years ago

Thanks Victor! I can confirm that it is fixed.