Advanced Popups in R Shiny Leaflet
<p>I have a dataset as follows</p>

<pre><code>itemcat country item Price date_today lat lng
Clothes Bangkok Shoes $5 2016-04-27 13.75 100.51 
Clothes Bangkok Tshirt $5 2016-04-27 13.75 100.51 
Clothes Bangkok Skirt $5 2016-04-27 13.75 100.51 
Clothes Bangkok Pants $5 2016-04-27 13.75 100.51
Food    Bangkok Chicken $2 2016-04-27 13.75 100.51
Food    Bangkok Milk   $2  2016-04-27 13.75 100.51
Clothes New York Shoes $5 2016-04-27 40.74 -73.98 
Clothes New York Tshirt $5 2016-04-27 40.74 -73.98 
Clothes New York Skirt $5 2016-04-27 40.74 -73.98 
Clothes New York Pants $5 2016-04-27 40.74 -73.98 
</code></pre>

<p>I have a shiny app that allows the user to pick an itemcat, pick a date, and leaflet will indicate the countries with price information available on the world map.</p>

<p>I want to create popups such that the pop ups are able to display the city and all the items and their prices when clicked on, e.g.:
<strong>City:</strong> Bangkok, <strong>Shoes</strong>:$5, <strong>Tshirt</strong>:$5, <strong>Skirt</strong>:$5, <strong>Pants</strong>:$5</p>

<p>But right now, I'm having trouble displaying these popups with my code. In particular, I don't know how to display multiple variable columns of ITEMS in the popups. The word "city:" pops up, but that is all.</p>

<pre><code>####USER INTERFACE####
ui &lt;- shinyUI(fluidPage(
tabsetPanel(
tabPanel("World Cost of Living",
sidebarLayout(position="right",
sidebarPanel(
selectInput("witem", "Select item of comparison", choices = c("Clothes", "Communication", "Income", "Outside Food", "Prepared Food", "Property Price", "Recreation", "Rent", "Transport", "Utilities")),
dateRangeInput("wdaterange", "Select Date Range", start = min(col$date_today), end = max(col$date_today), format = "yyyy-mm-dd", startview = "month", weekstart = 0, language = "en", separator = " to "),
dateInput("wdate", "Select Date", min = min(col$date_today), format = "yyyy-mm-dd", startview = "month", weekstart = 0, language = "en")),

 mainPanel(leafletOutput('map'))
))
)
)
)



####SERVER####

server &lt;- function(input, output, session){

  pal &lt;- colorQuantile("Blues", NULL, n = 5)
  output$map &lt;- renderLeaflet({
  prices&lt;-col[col$itemcat==input$witem &amp; col$date_today==input$wdate[1],]

  leaflet(prices) %&gt;% addTiles() %&gt;% addCircles(lng = ~lng, lat=~lat, stroke=TRUE, color = "black", weight=1, opacity = 0.2, fill = TRUE, fillColor = ~pal(infl), fillOpacity = 0.2 , radius = ~infl*30)
  })

  #~htmlEscape(country[lng==lng &amp; lat==lat])

  # Show a popup at the given location
  showPopup &lt;- function(itemcat, lat, lng, date) {
    selectedItem &lt;- col[col$itemcat == itemcat &amp; col$lat==lat &amp; col$lng==lng &amp; col$date_today==date,]
    content &lt;- as.character(tagList(
      tags$strong("City:", selectedItem$country),
      tags$strong(HTML(sprintf("%s, %s",
                               selectedItem$item, selectedItem$spore
      )))
    ))
    leafletProxy("map") %&gt;% addPopups(lng, lat, content, layerId = itemcat)
  }

  observe({
    leafletProxy("map") %&gt;% clearPopups()
    event &lt;- input$map_shape_click
    if (is.null(event))
      return()

    isolate({
      showPopup(event$id, event$lat, event$lng, event$date)
    })
  })

}
</code></pre>