0

My setup: I am using two selectizeInputs togehter with hcmap() in order to display a world map (this one custom/world-palestine-highres) where users can change the institute and the variable they want to look at. Hence, the map gets rendered often! In this process, I downloaded the map multiple times via testing/rendering the app till I found the options(highcharter.download_map_data = FALSE) while browsing through your repository - the vignette on how to use download_map_data is not that clear tbh. However, now the map gets rendered without downloading itself again --> perfect!

Now to my question: Where does the map get stored on the server when downloaded the first time? Because with my current setup, no user will download the map again (which is what I want), but what if we have to restart the server or move files? I just want to make sure that I dont have to service the app all the time in regards to map downloads.

EDIT#1: Code samples for JBKunst, as the new code doesn't show any data

My hcmap code I used before:

hcmap("custom/world-palestine-highres", data = datapool_credit, joinBy = c("hc-a2", "Country"), value = capital_variable,
      name = capital_variable,
      dataLabels = list(enabled = TRUE, format = '{point.name}'),
      borderColor = "#FAFAFA", borderWidth = 0.1,
      tooltip = list(valueDecimals = 0, valuePrefix = "€", valueSuffix = "")) %>%
  hc_mapNavigation(enabled = TRUE)

The new code as suggested by JBKunst:

highchart(type = "map") %>%
  hc_add_series(
    mapData = JS("Highcharts.maps['custom/world-palestine-highres']"),
    data = datapool_credit, joinBy = c("hc-key"), joinBy = c("hc-a2", "Country"), value = capital_variable,
    name = capital_variable,
    dataLabels = list(enabled = TRUE, format = '{point.name}'),
    borderColor = "#FAFAFA", borderWidth = 0.1,
    tooltip = list(valueDecimals = 0, valuePrefix = "€", valueSuffix = "")) %>%
  hc_mapNavigation(enabled = TRUE)

EDIT#2: structure of used data for the map (changed the numbers for data privacy reasons, but not the format)

> dput(head(datapool_credit))
structure(list(Country = c("AE", "AF", "AL", "AM", "AO", "AQ"
), PD = c(0.506010018321176, 64.350505, 8.94600128868667, 14.29401046096271, 
25.0439479, 3.5626)), .Names = c("Country", "PD"), class = c("data.table", 
"data.frame"), row.names = c(NA, -6L), .internal.selfref = <pointer: 0x244ccb8>)

Best regards, Martin

Martin G.
  • 159
  • 1
  • 15

1 Answers1

0

you can use something like https://github.com/jbkunst/shiny-apps/tree/master/highcharter-maps-performance

You don't need to store the map. Instead the user will read from https://code.highcharts.com/mapdata/custom/world-palestine-highres.js one time per session just like the highcharts example:

In your ui.R you need to add the map

# ui.R
...
tags$script(src = "https://code.highcharts.com/mapdata/custom/world-palestine-highres.js")
...

Then in the server.R don't use the hcmap, instead use highchart():

# server.R
...
highchart(type = "map") %>% 
  hc_add_series(
    mapData = JS("Highcharts.maps["custom/world-palestine-highres"]"),
    data = data, joinBy = c("hc-key")
  ) 
jbkunst
  • 3,009
  • 1
  • 22
  • 28
  • 1
    Thanks for your quick reply! As soon as I get back to the app, I will implement your proposed steps and report back to you – Martin G. Apr 27 '17 at 09:19
  • Hi, I tried to implement your code, but now the map doesn't show any data - just a plain grey map. Please see my edit#1 in my post for the two code samples, as the comment section is too small to post them here. – Martin G. May 03 '17 at 10:05
  • Try to put a `dput` of `head(datapool_credit)` in the question to see the data – jbkunst May 03 '17 at 13:48
  • Sorry for the really late reply - I added the dput in my question in EDIT#2. – Martin G. May 17 '17 at 10:20
  • 1
    Just want to add to @jbkunst's answer. As of Aug. 21, you can just use `download_map_data = FALSE` and keep using `hcmap`, in conjunction with the `tags$script` in `ui.R`. Nothing else needs to change. – Yifeng Mu Aug 21 '17 at 15:38