title: Issues with Nested ifelse to determine color of AwesomeMarkers
body: <p>I am trying to color awesomemarkers for leaflet in R by group according to <code>unique(df$type)</code>, although the current code is not grouping the way I envisioned. For example in dfnight, I would like all the &quot;Tacos&quot; markers to be green, &quot;Hamburger&quot; to be orange, and &quot;Elote&quot; to be darkblue no matter which options are selected from the picker. Right now, the colors change depending on what is selected. Any guidance or alternative way to achieve the same goal would be greatly appreciated. Many thanks!</p>
  <pre><code>library(leaflet)
  library(shiny)
  library(shinydashboard)
  library(dplyr)
  library(shinythemes)
  #Data Sample
  
  longN &lt;- c(-96.72363, -96.72880, -96.72700, -96.7259757, -96.7261564, -96.7260505)
  latN &lt;- c(17.06167, 17.06200, 17.06170, 17.0553262, 17.0543072,17.0548387 )
  nameN &lt;- c(&quot;jim&quot;, &quot;grant&quot;, &quot;pablo&quot;, &quot;sue&quot;, &quot;bob&quot;, &quot;frank&quot;)
  typeN &lt;- c(&quot;Tacos&quot;, &quot;Hamburger&quot;, &quot;Elotes&quot;, &quot;Tacos&quot;, &quot;Hamburger&quot;, &quot;Elotes&quot;)
  
  dfnight &lt;- data.frame(long=longN, lat=latN, name = nameN, type=typeN)
  
  
  longM &lt;- c(-96.72363, -96.72880, -96.72700, -96.7259757, -96.7261564, -96.7260505)
  latM &lt;- c(17.06167, 17.06200, 17.06170, 17.0553262, 17.0543072,17.0548387 )
  nameM &lt;- c(&quot;jim&quot;, &quot;grant&quot;, &quot;pablo&quot;, &quot;sue&quot;, &quot;bob&quot;, &quot;frank&quot;)
  typeM &lt;- c(&quot;Memelas&quot;,&quot;Tortas&quot;, &quot;Tacos&quot;, &quot;Memelas&quot;, &quot;Tortas&quot;,&quot;Tacos&quot;)
  
  
  # #icons
  
  dfmorn &lt;- data.frame(long=longM, lat=latM, name = nameM, type=typeM)
  
  getColorM&lt;-function(dfmorn){
    lapply(dfmorn$type, function(type) {
      ifelse(type == 'Tacos','green', 
             ifelse(type == 'Memelas', 'orange',
             ifelse(type == 'Chips', 'red',
             ifelse(type == 'Snacks', 'blue',
             ifelse (type == 'Sandwhiches', 'purple', 'black'
                              )))))
      
      
    })
  }
  
  getColorN &lt;- function(dfnight){
    lapply(dfnight$type, function(type) {
      ifelse(type == 'Tacos', 'green',
                    ifelse(type == 'Hamburguesa','orange',
                    ifelse (type == 'Elotes','darkblue',
                    ifelse (type == 'Plantanos','beige',
                    ifelse (type == 'Tamales','darkgreen',
                    ifelse (type == 'Tlayudas','cadetblue',
                    ifelse (type == 'Tortas','purple', 'black'
                                     )))))))
    })
  }
  
  iconsM &lt;- awesomeIcons(
    icon = 'ios-close',
    iconColor = 'black',
    library = 'ion',
    markerColor = getColorM(dfmorn))
  
  iconsN &lt;- awesomeIcons(
    icon = 'ios-close',
    iconColor = 'black',
    library = 'ion',
    markerColor = getColorN(dfnight))
  
  
  #ui 
  ui &lt;- fluidPage(theme = shinytheme(&quot;darkly&quot;),
    titlePanel(title = &quot;Street Food in Historic Center of Oaxaca, Mexico&quot;),
    sidebarLayout(
      sidebarPanel(
        selectInput(
          inputId = &quot;time&quot;,
          label = &quot;Select Time&quot;,
          choices = c(&quot;Day&quot;, &quot;Night&quot;),
          selected = &quot;Day&quot;
        ),
        selectInput(
          inputId = &quot;food&quot;,
          label = &quot;Type of Food&quot;,
          choices = unique(dfmorn$type),
          selected = dfmorn$food[1:5],
          multiple = TRUE)),
      mainPanel(h3(&quot;Map&quot;), leafletOutput(&quot;map&quot;, width = &quot;800&quot;, height = &quot;600&quot;)))
  )
  
  #server
  server &lt;- function(input, output, session){ 
    
    observeEvent(input$time, {
      
      if(input$time == &quot;Day&quot;) choices &lt;- unique(dfmorn$type)
      else choices &lt;- unique(dfnight$type)
      
      updateSelectInput(
        inputId = &quot;food&quot;,
        label = &quot;Type of Food&quot;,
        choices = choices,
        select=choices[1:3]
      )
    })
    
    dfmrn &lt;- eventReactive(input$food, {
      if(input$time == &quot;Day&quot;) df &lt;- dfmorn
      else df &lt;- dfnight
      df %&gt;% dplyr::filter(type %in% input$food)
    })
    
    observe({print(dfmrn())})
    
    output$map = renderLeaflet({
      req(dfmrn())
      leaflet(data = dfmrn()) %&gt;%
        setView(lng = -96.725, lat = 17.0618, zoom =14)%&gt;%
        addTiles() 
    })
    
    observeEvent(input$food, {
      if(input$time == &quot;Day&quot;) icons &lt;- iconsM
      else icons &lt;- iconsN
      leafletProxy(&quot;map&quot;, session) %&gt;%
        clearShapes() %&gt;%
        clearMarkers() %&gt;%
        addAwesomeMarkers( 
          data = dfmrn(),
          lng = ~long,
          lat = ~lat,
          icon = icons,
          label = ~as.character(type)
        )
    })
    
  }
  
  #Run the application 
  shinyApp(ui = ui , server = server)
  </code></pre>
  <p>Updated code using list()</p>
  <pre><code>getColorM&lt;- list(&quot;Tacos&quot;= &quot;green&quot;, &quot;Memelas&quot; = &quot;orange&quot;, &quot;Tortas&quot; = &quot;purple&quot;)
                   #&quot;Chips&quot; = &quot;red&quot;, &quot;Snacks&quot;= &quot;blue&quot;, )
  
  getcolorN &lt;-list(&quot;Tacos&quot;= &quot;green&quot;, &quot;Hamburger&quot; = &quot;orange&quot;, &quot;Elotes&quot; = &quot;darkblue&quot;)
                   #&quot;Papas&quot; = &quot;red&quot;, &quot;Antojitos&quot;= &quot;blue&quot;, &quot;Tortas&quot; = &quot;purple&quot;,
                   #&quot;Marquesitas&quot;= &quot;pink&quot;, &quot;Platanos&quot; = &quot;biege&quot;, &quot;Antojitos&quot;= &quot;blue&quot;, &quot;Tamales&quot; = &quot;darkgreen&quot;, &quot;Tlayudas&quot; = &quot;cadetblue&quot;)
  
  iconsM &lt;- awesomeIcons(
    icon = 'ios-close',
    iconColor = 'black',
    library = 'ion',
    markerColor &lt;- getColorM[dfmorn$type] )
  
  iconsN &lt;- awesomeIcons(
    icon = 'ios-close',
    iconColor = 'black',
    library = 'ion',
    markerColor &lt;-getcolorN[dfnight$type])
  </code></pre>
  <p><a href="https://i.stack.imgur.com/86wvU.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/86wvU.jpg" alt="Red Color Markers" /></a></p>