Closed OlexiyPukhov closed 1 year ago
what is 'canvas mode of rendering'?
It's a way of rendering that makes it less laggy when plotting a lot of circles or markers. It's less well known but it works really well. Here is something about it on leaflet. https://stackoverflow.com/questions/49235357/is-there-a-way-to-implement-canvas-as-renderer-in-leaflet-r-instead-of-svg
I usually recommend people to use mapdeck layers on top of a google map, as that's far more performant again.
It's a good method, but it doesn't have a function to add circles. Specifically, I want to add all 5000 pharmacies in Ontario on a map and then display information parsed as HTML about it. Mapbox doesn't have that functionality, but leaflet does. Was wondering if its also possible to get that functionality with googleway, but it can't render more than 150 markers/circles.
mapdeck::add_scatterplot()
will render circles, and it can handle a million points easily
Okay, I'll try that and then will update you. Thanks for the help.
I got it to work, but the tooltip is not showing up. I initially tried add_scatterplot(), but it did not resize the size of the circles when zooming into the map. I ended up going with pointclouds, since they do resize when you zoom into the map. However, I can't get the tooltip to show. Here is my code so far:
output$map <- renderGoogle_map({
google_map(data = pharmacies_data_geocleaned, key = map_key ) %>%
mapdeck::add_dependencies() %>%
mapdeck::add_pointcloud(
data = pharmacies_data_geocleaned,
lon = "long",
lat = "lat",
radius = 10,
tooltip = pharmacies_data_geocleaned$label,
auto_highlight = TRUE,
update_view = TRUE,
id = "google_map",
focus_layer = TRUE
)
})
}
ChatGPT is confused and is not sure what to do. I've also tried tooltip = "label", but that also doesn't work. Here are the first 5 rows of pharmacies_data_geocleaned$label (this is all public information)
[1] "Name: 108 Stop Pharmacy
Type: Independent
Address: 13444 108 Ave Surrey, BC V3T 2K1
Manager: Vesna Vlacina Ljepic
Phone: (604) 957-0711"
[2] "Name: 360care Denman Pharmacy
Type: Independent
Address: 683 Denman St Vancouver, BC V6G 2L3
Manager: Cathy Wang
Phone: (604) 683-6933"
[3] "Name: 49th Parallel Pharmacy
Type: Independent
Address: 15229 Russell Ave White Rock, BC V4B 5C3
Manager: Mary Mani
Phone: (778) 294-7737"
[4] "Name: Aaronson's Pharmacy (Cook St.) Ltd.
Type: Independent
Address: 1711 Cook St. Victoria, BC V8T 3P2
Manager: Andrew Formosa
Phone: (250) 383-6511"
[5] "Name: Abbotsford Pharmacy
Type: Independent
Address: 104 - 2596 McMillan Rd Abbotsford, BC V3G 1C4
Manager: Benyamin Ghali
Phone: (778) 314-1014"
tooltip = "label"
should work.
Does the example in ?add_pointcloud
work?
df <- capitals
df$z <- sample(10000:10000000, size = nrow(df))
googleway::google_map(key = "abc") %>%
mapdeck::add_dependencies() %>%
mapdeck::add_pointcloud(
data = df
, lon = 'lon'
, lat = 'lat'
, elevation = 'z'
, layer_id = 'point'
, fill_colour = "country"
, tooltip = "country"
)
It does not work. For reference, I am trying to do this in a shiny app. The only 2 things that I have changed so far from the example code you linked above is changing it to rendergoogle_map and added my API key. It gives me an error: here is the output and here's my whole code.
library(rio) library(ggplot2) library(tidyverse) library(tidygeocoder) library(maps) library(mapdeck) library(shiny) library(htmltools) library(janitor) library(googleway) library(mapboxer) library(shinydashboard)
ui <- fluidPage( titlePanel("Testing Google Maps"), google_mapOutput(outputId = "map", width = "100%", height = "800px"), )
server <- function(input, output) { pharmacies_data_geocleaned = read_rds("map_bc.rds")
map_key <- "xxx"
df <- capitals
df$z <- sample(10000:10000000, size = nrow(df))
output$map <- googleway::renderGoogle_map({(key = map_key) %>%
mapdeck::add_dependencies() %>%
mapdeck::add_pointcloud(
data = df
, lon = 'lon'
, lat = 'lat'
, elevation = 'z'
, layer_id = 'point'
, tooltip = "country"
)})
}
shinyApp(ui, server)
Listening on http://127.0.0.1:4885 Warning: Error in $: $ operator is invalid for atomic vectors 104: unique 103: mapdeck::add_dependencies 102: lapply 101: sapply 100: addDependency 99: mapdeck::add_pointcloud 98: %>% 97: :: htmlwidgets shinyRenderWidget [C:/Users/Administrator/Desktop/R/BC Pharmaceutical Census/BC_Map_Server_Circles_google_testv2.R#27] 96: func 83: renderFunc 82: output$map 1: runApp
you haven't included the google_map()
call.
It does not work
Have you tried the code outside of shiny?
Yes, but it crashes my RStudio instead.
can you make sure you have the latest version of sfheaders
please - it was updated on CRAN last week and resolve this issue on some Windows machines.
Same issue.
sessionInfo()
?
After running the initial library lines:
do you have the same versions of these:
devtools::session_info("sfheaders")
─ Packages ──────────────────────────────────────────────────────────────────────────────────────────
package * version date (UTC) lib source
geometries 0.2.2 2023-02-28 [1] CRAN (R 4.2.0)
Rcpp 1.0.10 2023-01-22 [1] CRAN (R 4.2.0)
sfheaders 0.4.2 2023-03-03 [1] CRAN (R 4.2.0)
[1] /Library/Frameworks/R.framework/Versions/4.2/Resources/library
The same.
does this crash?
library(mapdeck)
df <- capitals
df$z <- sample(10000:10000000, size = nrow(df))
mapdeck::mapdeck() %>%
mapdeck::add_pointcloud(
data = df
, lon = 'lon'
, lat = 'lat'
, elevation = 'z'
, layer_id = 'point'
, fill_colour = "country"
, tooltip = "country"
)
It gets stuck computing something.
Tried again with a fresh R session: this time, it crashed.
can you try
remotes::install_github("SymbolixAU/spatialwidget")
remotes::install_github("SymbolixAU/mapdeck")
Still crashes :(
BUT THE SHINY WORKS!
However, making the fill a string doesn't seem to work. But thank you so much for all the help!
Thank you for your help so far! I asked ChatGPT 4 released just today and it solved my issue. Thanks for your help!
Is there anyway to get canvas mode of rendering?