Hello,
I am not the most skilled at R, but I am trying to make a map with leaflet, and I cannot figure out how to get the text in my labels to wrap. I'm providing a simplified code using Sprintf that has my label. Ive tried str_wrap for my variable... but maybe i don't fully understand how to use that. I've also tried inserting brackets like div style = 'width: 250; height: 250; word-wrap: break-word'></div. If anyone has advice, I would really appreciate it.
x <- c("this is a lot of text", "this is really long text that i need to break up", "wow i cannot believe how long this text is, i wish it would not make my label so big")
labels2 <- sprintf("Description: %s",
x) %>%
lapply(htmltools::HTML)
***I am not providing the leaflet code in a replicable way, because I think it'd have to upload a shapefile... But let me know if that is an issue. Below is the code I am using for my map making.
map <-leaflet(sites) %>%
clearBounds() %>%
addProviderTiles(providers$Esri.WorldImagery) %>%
addPolygons(
fillColor = ~pal(Effort),
weight = 1,
opacity = .8,
color = ~pal(Effort),
highlightOptions = highlightOptions(
weight = 2,
color = ~pal(Effort),
fillOpacity = 0.7),
label = labels,
labelOptions = labelOptions(
style = list(padding = "3px 8px"),
direction = "auto")) %>%
addLegend("bottomright",
title = "Level of Effort",
pal = pal,
values = ~Effort,
opacity = 1)