library(leaflet)
library(htmlTable)
df <- read.csv(textConnection(
"Name,Lat,Long
Samurai Noodle,47.597131,-122.327298
Kukai Ramen,47.6154,-122.327157
Tsukushinbo,47.59987,-122.326726"
))
# Use html table tags. Ugly and prone to errors
leaflet(df) %>% addTiles() %>%
addMarkers(~Long, ~Lat, popup = ~paste("<table>
<thead><tr><td>Name</td><td>Longitude</td><td>Lattitude</td></tr></thead>
<tbody><tr><td>", Name, "</td><td>", Long, "</td><td>", Lat, "</td></tr></tbody>
</table"))
# Use htmlTables
leaflet(df) %>% addTiles() %>%
addMarkers(~Long, ~Lat, popup = ~htmlTable(data.frame(Name, Long, Lat)))
--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shiny-discuss/2dcd0f74-18e1-49e2-b90c-949537a14a56%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
popup = apply(df, 1, function(row) htmlTable(row))ok this is a bad solution
lapply traverses the df differently than leaflet does.# Use htmlTables
df %>% leaflet() %>% addTiles() %>%
addMarkers(~Long, ~Lat, popup = lapply(seq_along(df), function(row) htmlTable(df[row, ])))
For large dataframes the lat and long are correct but you can see completely wrong rows in the popups.
--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shiny-discuss/29bd878a-5fd4-479a-bdb0-79cf63807a14%40googlegroups.com.