R传单中的图标未加载(空白图片)(带有光泽) [英] Icons not loading (empty image) in R Leaflet with Shiny

查看:111
本文介绍了R传单中的图标未加载(空白图片)(带有光泽)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

[R-3.4.3 64位,RStudio,shinydashboard_0.6.1,shiny_1.0.5,leaflet.extras_0.2,Chrome]

[R-3.4.3 64-bit, RStudio, shinydashboard_0.6.1, shiny_1.0.5, leaflet.extras_0.2, Chrome]

我正在使用Shiny制作要在R/Leaflet中使用的图标,而我所得到的只是下面的内容,但我不知道为什么:

I'm making icons to use in R/Leaflet with Shiny and all im getting is the below, but i've no idea why:

这是使用此处的玩具示例:

oceanIcons <- iconList(
  ship = makeIcon("ferry-18.png", "ferry-18@2x.png", 18, 18),
  pirate = makeIcon("danger-24.png", "danger-24@2x.png", 24, 24)
)

# Some fake data
df <- sp::SpatialPointsDataFrame(
  cbind(
    (runif(20) - .5) * 10 - 90.620130,  # lng
    (runif(20) - .5) * 3.8 + 25.638077  # lat
  ),
  data.frame(type = factor(
    ifelse(runif(20) > 0.75, "pirate", "ship"),
    c("ship", "pirate")
  ))
)

leaflet(df) %>% addTiles() %>%
  # Select from oceanIcons based on df$type
  addMarkers(icon = ~oceanIcons[type])

以及以下,使用runApp(shinyApp(ui, server), launch.browser = TRUE)时具有不同但相似的玩具数据;

And the following, with different but similar toy data, when using runApp(shinyApp(ui, server), launch.browser = TRUE);

推荐答案

请参见 makeIcon的文档.作为第一个参数,它期望:

See the documentation for makeIcon. As the first argument it expects:

iconUrl: the URL or file path to the icon image

因此,仅当您在工作目录中包含png,更改路径以使其包含硬盘驱动器上图像的正确路径时,或者您可以使用URL时,代码才起作用.因此,一个可行的示例是:

So your code will only work if you either have the png in your working directory, alter the path so it contains the correct path to the image on your hard drive, or you could use an URL. So a working example would be:

  # Make a list of icons. We'll index into it based on name.
    oceanIcons <- iconList(
      ship = makeIcon("http://globetrotterlife.org/blog/wp-content/uploads/leaflet-maps-marker-icons/ferry-18.png", 18, 18),
      pirate = makeIcon("http://globetrotterlife.org/blog/wp-content/uploads/leaflet-maps-marker-icons/danger-24.png", 24, 24)
    )

    # Some fake data
    df <- sp::SpatialPointsDataFrame(
      cbind(
        (runif(20) - .5) * 10 - 90.620130,  # lng
        (runif(20) - .5) * 3.8 + 25.638077  # lat
      ),
      data.frame(type = factor(
        ifelse(runif(20) > 0.75, "pirate", "ship"),
        c("ship", "pirate")
      ))
    )

    leaflet(df) %>% addTiles() %>%
      # Select from oceanIcons based on df$type
      addMarkers(icon = ~oceanIcons[type])

希望这会有所帮助!

这篇关于R传单中的图标未加载(空白图片)(带有光泽)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆