3
votes

I am using awesomeIcons() where I found a hospital icon ('hospital-o'). However, the icon turns out to be black. Using the code below, I am unable to change its color to white.

library(dplyr)
library(DT)
library(flexdashboard)
library(leaflet)
library(leaflet.extras)
library(reshape2)
library(shiny)

icons <- awesomeIcons(
          icon = 'hospital-o',
          lib = 'fa',
          markerColor = getColor(DATASET))

Where getColor() is the following function:

  getColor <-
  function(DATASET) {
    sapply(DATASET$VAR, function(VAR) {
    if(VAR == 0 | is.na(VAR) | is.nan(VAR)) {"gray"}
    else if(VAR <= 2){"darkgreen"}
    else if(VAR <= 4){"green"}
    else if(VAR <= 6){"orange"}
    else if(VAR <= 10){"red"}
    else {"darkred"}
    })
  }

The color function is working (i.e., gray, green, red, markers). I have tried something like this (and also implementing color codes), without result:

icons <- awesomeIcons(
          icon = 'hospital-o',
          lib = 'fa',
          iconColor = "white",
          markerColor = getColor(DATASET))

Dummy data

NAME    VAR latitude    longitude
A   1   51.792  4.682
B   12  52.214  6.894
C   6   51.982  5.148

Making map:

map <- leaflet(DATASET) %>%          
addTiles() %>% 
addAwesomeMarkers(lng = ~longitude, lat = ~latitude, icon = icons, label = ~as.character(DATASET$NAME),
                popup = paste0("<strong>Name: </strong>", DATASET$NAME, "<br>","<strong>VAR: </strong>", DATASET$VAR)) %>% 
     addMarkers(lng = longitude, lat = latitude) %>%
addProviderTiles(providers$nlmaps.pastel, group = "Pastel") %>%
addMiniMap(toggleDisplay = T, minimized = T, position = "bottomright") %>%
addLayersControl(
  baseGroups = c("Pastel"), 
  options = layersControlOptions(collapsed = F), position = "topleft") %>%
       addMarkers(lng = longitude, lat = latitude)

Can somebody help me? Thank you in advance!

1
Can you make your post reproducible? As it is we can't test your code.MLavoie
EDIT: libraries, dummy dataset and map plotting code.JohnDoedel
try this: iconColor = "#FFFFFF".MLavoie

1 Answers

2
votes

Implementing iconColor = "#FFFFFF" in awesomeIcons()does the trick! So the code looks like this:

  icons <- awesomeIcons(
  icon = 'hospital-o',
  lib = 'fa',
  iconColor = "#FFFFFF",
  markerColor = getColor(DATASET))

I thought I already tried this. Thanks, MLavoie!