jbkunst / highcharter

R wrapper for highcharts
http://jkunst.com/highcharter/
Other
718 stars 147 forks source link

Heatmap slow render on enabled dataLabels #723

Closed aha-incom closed 1 year ago

aha-incom commented 2 years ago

Hi, first of all thanks for a great package! The proxy functions included in the develop version is really useful and it's easy to implement new proxies on top.

I however have a problem with the render time for heatmaps, when I set DataLabels = list(enabled = TRUE) for a Shiny app containing a lot of heatmaps.

I don't know if there exists a solution, but it seems like it's the rendering of DataLabels that is slowing the process down. When enabled = FALSE the render is a couple of seconds whereas for TRUE it's easy ~15 seconds.

I have found a original issue from the HighCharts JS package: https://stackoverflow.com/questions/43217023/highcharts-heatmap-chart-labels-render-extremely-slow. I've used the "solutinon" 2 and 3 but 4 is more of the back-end of the package.

library(dplyr)
library(shiny)
library(highcharter)
library(purrr)

data <- 
  dplyr::tibble(
    x = rep(1:48, 4),
    y = c(rep("A",48), rep("B", 48), rep("C", 48), rep("D", 48)),
    value = round(rnorm(48*4, mean = 200, sd = 10),2)
  )
number_of_plots <- 30
shinyApp(
  ui = fluidPage(
    purrr::map(1:number_of_plots, function(.x) {
      column(12, highcharter::highchartOutput(paste0("heatmap",.x), height = "100%"))
    })
  ),
  server = function(input, output) {

    purrr::walk(1:number_of_plots, .f = function(.x) {
      output[[paste0("heatmap",.x)]] <- 
        highcharter::renderHighchart({

          highcharter::highchart() %>%
            highcharter::hc_yAxis(categories = list("A", "B", "C", "D")) %>%
            highcharter::hc_xAxis(categories = data$x) %>%
            highcharter::hc_add_series(data = data,
                                       type = "heatmap",
                                       highcharter::hcaes(x, y, value),
                                       fast = TRUE) %>% 
            highcharter::hc_plotOptions(heatmap = list(
              dataLabels = list(
                enabled = TRUE,
                shadow = FALSE,
                align = "center",
                allowOverlap = TRUE,
                style = list(fontSize = "8px",
                             color = "black",
                             textOutline = NULL,
                             fontWeight = NULL
                )
              ),
              borderWidth = 0.5,
              borderColor = "#000000"
            )) %>% 
            highcharter::hc_chart(height = 135) %>% 
            highcharter::hc_legend(enabled = FALSE)
        })

    })
  }
)

sessionInfo :

R version 4.0.3 (2020-10-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19042)

Matrix products: default

locale:
[1] LC_COLLATE=English_United Kingdom.1252  LC_CTYPE=English_United Kingdom.1252    LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C                           
[5] LC_TIME=English_United Kingdom.1252    

attached base packages:
[1] stats     graphics  grDevices datasets  utils     methods   base     

other attached packages:
[1] purrr_0.3.4            highcharter_0.8.2.9000 shiny_1.6.0            dplyr_1.0.7           

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.7        jquerylib_0.1.4   bslib_0.2.5.1     pillar_1.6.2      compiler_4.0.3    later_1.3.0       xts_0.12.1        remotes_2.4.0     tools_4.0.3      
[10] digest_0.6.27     lattice_0.20-41   jsonlite_1.7.2    lubridate_1.7.10  lifecycle_1.0.0   tibble_3.1.3      pkgconfig_2.0.3   rlang_0.4.11      igraph_1.2.6     
[19] cli_3.0.1         yaml_2.2.1        curl_4.3.2        fastmap_1.1.0     withr_2.4.2       stringr_1.4.0     sass_0.4.0        generics_0.1.0    vctrs_0.3.8      
[28] htmlwidgets_1.5.3 grid_4.0.3        tidyselect_1.1.1  data.table_1.14.0 glue_1.4.2        R6_2.5.1          fansi_0.5.0       TTR_0.24.2        tidyr_1.1.3      
[37] magrittr_2.0.1    backports_1.2.1   promises_1.2.0.1  ellipsis_0.3.2    htmltools_0.5.1.1 rlist_0.4.6.1     assertthat_0.2.1  quantmod_0.4.18   mime_0.11        
[46] xtable_1.8-4      renv_0.12.5       httpuv_1.6.2      utf8_1.2.2        stringi_1.7.3     cachem_1.0.6      broom_0.7.9       crayon_1.4.1      zoo_1.8-9  
stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. Feel free to reopen it if you find it necessary.