[R-3.4.3 64-bit, RStudio, shinydashboard_0.6.1, shiny_1.0.5, leaflet.extras_0.2, Chrome]
I'm making icons to use in R/Leaflet with Shiny and all im getting is the below, but i've no idea why:
This is using the toy example from here:
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])
And the following, with different but similar toy data, when using runApp(shinyApp(ui, server), launch.browser = TRUE)
;
See the documentation for makeIcon. As the first argument it expects:
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:Hope this helps!