0

我的设置:我使用两个一selectizeInputs起来hcmap()显示世界地图(这个自定义/世界巴勒斯坦高地),用户可以在其中更改研究所和他们想要查看的变量。因此,地图经常被渲染!在这个过程中,我通过测试/渲染应用程序多次下载了地图,直到我options(highcharter.download_map_data = FALSE)在浏览您的存储库时找到了 -关于如何使用的小插曲download_map_data并不是那么清楚。但是,现在地图无需再次下载即可渲染 -> 完美!

现在我的问题是:第一次下载地图时,地图在哪里存储在服务器上?因为在我当前的设置下,没有用户会再次下载地图(这是我想要的),但是如果我们必须重新启动服务器或移动文件怎么办?我只是想确保我不必一直为应用程序提供地图下载服务。

EDIT#1: JBKunst 的代码示例,因为新代码不显示任何数据

我之前使用的 hcmap 代码:

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)

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)

编辑#2:地图使用数据的结构(出于数据隐私原因更改了数字,但不是格式)

> 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>)

最好的问候,马丁

4

1 回答 1

0

你可以使用类似https://github.com/jbkunst/shiny-apps/tree/master/highcharter-maps-performance

您不需要存储地图。相反,用户将在每个会话中读取https://code.highcharts.com/mapdata/custom/world-palestine-highres.js一次,就像 highcharts 示例一样:

在您ui.R需要添加地图

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

然后在server.R不使用hcmap,而是使用highchart()

# server.R
...
highchart(type = "map") %>% 
  hc_add_series(
    mapData = JS("Highcharts.maps["custom/world-palestine-highres"]"),
    data = data, joinBy = c("hc-key")
  ) 
于 2017-04-26T15:47:40.003 回答