r-spatial / leafgl

R package for fast web gl rendering for leaflet
Other
263 stars 31 forks source link

src=TRUE issue with addGL... when using Shiny #71

Closed h-a-graham closed 2 years ago

h-a-graham commented 2 years ago

Hi @tim-salabim,

Further to the previous issue (https://github.com/r-spatial/leafgl/issues/70), where you suggested using the src=TRUE with addGlPolylines, addGlPoints, etc. in order to improve the performance. This works great for me apart from when in a shiny app.

The following works when src=FALSE but when TRUE no features are rendered and the error message: Unknown method addGlifyPointsSrc is given. Here is the message from Chrome: image

library(leaflet)
library(leafgl)
library(sf)
#> Linking to GEOS 3.10.1, GDAL 3.4.0, PROJ 8.2.0; sf_use_s2() is TRUE
library(shiny)

n = 1e6

df1 = data.frame(id = 1:n,
                 x = rnorm(n, 10, 3),
                 y = rnorm(n, 49, 1.8))

pts = st_as_sf(df1, coords = c("x", "y"), crs = 4326)

options(viewer = NULL) # view in browser

m = leaflet() %>%
  addProviderTiles(provider = providers$CartoDB.DarkMatter) %>%
  addGlPoints(data = pts, group = "pts", src=TRUE) %>% # src set to TRUE
  setView(lng = 10.5, lat = 49.5, zoom = 4) %>%
  addLayersControl(overlayGroups = "pts")

ui <- fluidPage(
  leafglOutput("mymap")
)
#> Registered S3 method overwritten by 'jsonlite':
#>   method     from   
#>   print.json jsonify

server <- function(input, output, session) {
  output$mymap <- renderLeaflet(m)
}

shinyApp(ui, server)
#> 
#> Listening on http://127.0.0.1:8785

Created on 2022-03-18 by the reprex package (v2.0.0)

Do you know of any workarounds for this?

Many thanks! Hugh

tim-salabim commented 2 years ago

I'll look into it over the weekend.

On Fri, Mar 18, 2022, 13:29 Hugh Graham @.***> wrote:

Hi @tim-salabim https://github.com/tim-salabim,

Further to the previous issue (#70 https://github.com/r-spatial/leafgl/issues/70), where you suggested using the src=TRUE with addGlPolylines, addGlPoints, etc. in order to improve the performance. This works great for me apart from when in a shiny app.

The following works when src=FALSE but when TRUE no features are rendered and the error message: Unknown method addGlifyPointsSrc is given. Here is the message from Chrome: [image: image] https://user-images.githubusercontent.com/43027949/159002633-eb815df9-35fa-478e-99d7-1d646bd96bfb.png

library(leaflet) library(leafgl) library(sf)#> Linking to GEOS 3.10.1, GDAL 3.4.0, PROJ 8.2.0; sf_use_s2() is TRUE library(shiny) n = 1e6 df1 = data.frame(id = 1:n, x = rnorm(n, 10, 3), y = rnorm(n, 49, 1.8)) pts = st_as_sf(df1, coords = c("x", "y"), crs = 4326)

options(viewer = NULL) # view in browser m = leaflet() %>% addProviderTiles(provider = providers$CartoDB.DarkMatter) %>% addGlPoints(data = pts, group = "pts", src=TRUE) %>% # src set to TRUE setView(lng = 10.5, lat = 49.5, zoom = 4) %>% addLayersControl(overlayGroups = "pts") ui <- fluidPage( leafglOutput("mymap") )#> Registered S3 method overwritten by 'jsonlite':#> method from #> print.json jsonify server <- function(input, output, session) { output$mymap <- renderLeaflet(m) }

shinyApp(ui, server)#> #> Listening on http://127.0.0.1:8785

Created on 2022-03-18 by the reprex package https://reprex.tidyverse.org (v2.0.0)

Do you know of any workarounds for this?

Many thanks! Hugh

— Reply to this email directly, view it on GitHub https://github.com/r-spatial/leafgl/issues/71, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAVSBQFK7SCITGP36FSFZOTVARZKHANCNFSM5RBWM46A . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you were mentioned.Message ID: @.***>

h-a-graham commented 2 years ago

Thankyou Tim!

tim-salabim commented 2 years ago

Should work now. Was a naming clash between the standard htmlDependencies and the deps used when src = TRUE. Feel free to re-open if you still have problems...

h-a-graham commented 2 years ago

Thank you Tim, I really appreciate this! I'm sure it's working great now but will confirm on Monday!

h-a-graham commented 2 years ago

Hi Tim, just to confirm that this did the trick and works as expected, thanks again!