Learn R Programming

berryFunctions (version 1.22.5)

popleaf: create leaflet popup box info

Description

combine data.frame columns into a leaflet popup-box compatible format

Usage

popleaf(
  df,
  sel = colnames(df),
  truncate = NULL,
  tstring = "[...]",
  exclude_geometry = TRUE,
  na.rm = FALSE
)

Value

Vector with character strings

Arguments

df

Data.frame

sel

Columns to be selected (Names or index or TRUE/FALSE vector). DEFAULT: colnames(df)

truncate

Numeric: number of characters beyond which to truncate columns. DEFAULT: NULL (no truncation)

tstring

Charstring to add at the end if truncated. DEFAULT: "[...]"

exclude_geometry

Remove column with the name "geometry" (as in sf objects) from the display? DEFAULT: TRUE

na.rm

Exclude NA entries from the display? DEFAULT: FALSE

Author

Berry Boessenkool, berry-b@gmx.de, Apr 2017

See Also

Examples

Run this code
dat <- data.frame(a=14:16, b=letters[14:16], c=LETTERS[14:16],
                 lat=c(52.58,53.45,52.4), lon=c(6.34,7.23,13.05))
popleaf(dat)
dat$display <- popleaf(dat, 1:4)

if (FALSE)  # Excluded from CRAN checks
library(leaflet)
leaflet(dat) %>% addTiles() %>% addCircleMarkers(~lon, ~lat, popup=~display)


dat[1,1] <- "Very long string I'd rather have truncated"
popleaf(dat, 1:3)
popleaf(dat, 1:3, truncate=16)
popleaf(dat, 1:3, truncate=16, tstring="--")

Run the code above in your browser using DataLab