Visualize bubbles on a map, using hc_add_series_map() instead of hcmap()

Hi everybody.
I am trying to visualize a bubble map, using highcharter.

I did it perfectly, using this code

library(highcharter)
library(tidyverse)

hcmap("custom/africa") %>%
hc_add_series(data = fake_data, type = "mapbubble", maxSize = '10%', color = 
"Red", showInLegend = FALSE) %>% 
hc_legend(enabled = FALSE)  

My data

> dput(fake_data)
structure(list(country = c("DZ", "CD", "ZA", "TZ"), lat = c(28.033886, 
-4.038333, -30.559482, -6.369028), lon = c(1.659626, 21.758664, 
22.937506, 34.888822), name = c("Algeria", "Congo, Dem. Rep", 
"South Africa", "Tanzania"), z = c(20, 5, 10, 1)), class = c("spec_tbl_df", 
"tbl_df", "tbl", "data.frame"), row.names = c(NA, -4L), spec = 
structure(list(
cols = list(country = structure(list(), class = c("collector_character", 
"collector")), lat = structure(list(), class = c("collector_double", 
"collector")), lon = structure(list(), class = c("collector_double", 
"collector")), name = structure(list(), class = c("collector_character", 
"collector")), z = structure(list(), class = c("collector_double", 
"collector"))), default = structure(list(), class = c("collector_guess", 
"collector")), skip = 1), class = "col_spec"))

External geo data for Africa originally comes from this source and used with hcmap() .

But I transform it into RDS and use locally. Available here.

My problem that I cannot use my code and external data due to corporate IT security restrictions. I cannot deploy this code with Shiny/RMarkdown on Connect, it is blocked. The code works perfectly on pure RMarkdown report even on Connect, but when I add runtime: shiny it fails on Connect for obvious reason.

02/23 14:47:27.939

trying URL 'https://code.highcharts.com/mapdata/custom/africa.js'

02/23 14:47:28.199

Quitting from lines 16-22 (Test.Rmd)

02/23 14:47:28.200

02/23 14:47:28.201

Warning: Error in download.file: cannot open URL 'https://code.highcharts.com/mapdata/custom/africa.js'

I see two potential solutions: rewrite a code without this hcmap(), which pulls external data, substituting it with hc_add_series_map() or somehow save this African data (I did in RDS) and read from project directory.

First approach failed.

africa_map_data <- readRDS("africa_map_data.RDS")

And use the hc_add_series_map() with local data instead of hcmap() .

highchart() %>%
hc_add_series_map(
map = africa_map_data,
df = fake_data,
value = "z",
joinBy = c("hc-a2", "country"),
type = "mapbubble",
maxSize = '10%',
color = "Red"
)

But it does not work well, I get a mess.

My question: How to create a bubble map with hc_add_series_map() (or any other way) without hcmap() or how to use locally saved data with hcmap() to be able to run it as shiny element on Connect with some firewall.

Thanks!

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.