Skip to content

Commit

Permalink
lintr
Browse files Browse the repository at this point in the history
  • Loading branch information
trafficonese committed Sep 1, 2024
1 parent 87604d3 commit 9fd266a
Show file tree
Hide file tree
Showing 20 changed files with 274 additions and 221 deletions.
3 changes: 2 additions & 1 deletion R/tangram.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ tangram_deps <- function() {
#' }
addTangram <- function(map, scene = NULL, layerId = NULL, group = NULL,
options = NULL) {
if ((is.null(scene) || !is.character(scene) || (!gsub(".*\\.", "", scene) %in% c("yaml", "zip")))) {
if ((is.null(scene) || !is.character(scene) ||
(!gsub(".*\\.", "", scene) %in% c("yaml", "zip")))) {
stop(
"The scene must point to a valid .yaml or .zip file.\n",
"See the documentation for further information."
Expand Down
9 changes: 6 additions & 3 deletions R/timeslider.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ timesliderDependencies <- function() {
list(
htmlDependency(
"lfx-timeslider", "1.0.0",
src = system.file("htmlwidgets/lfx-timeslider", package = "leaflet.extras2"),
src = system.file("htmlwidgets/lfx-timeslider",
package = "leaflet.extras2"),
stylesheet = "jquery-ui.css",
script = c(
"jquery-ui.min.js",
Expand Down Expand Up @@ -54,7 +55,8 @@ timesliderDependencies <- function() {
#' setView(-72, 22, 4)
addTimeslider <- function(map, data, radius = 10,
stroke = TRUE, color = "#03F",
weight = 5, opacity = 0.5, fill = TRUE, fillColor = color,
weight = 5, opacity = 0.5, fill = TRUE,
fillColor = color,
fillOpacity = 0.2, dashArray = NULL,
popup = NULL, popupOptions = NULL,
label = NULL, labelOptions = NULL,
Expand Down Expand Up @@ -107,7 +109,8 @@ addTimeslider <- function(map, data, radius = 10,

## Add Deps and invoke Leaflet
map$dependencies <- c(map$dependencies, timesliderDependencies())
invokeMethod(map, NULL, "addTimeslider", data, options, popupOptions, labelOptions) %>%
invokeMethod(map, NULL, "addTimeslider", data, options,
popupOptions, labelOptions) %>%
expandLimits(bbox[c(2, 4)], bbox[c(1, 3)])
}

Expand Down
10 changes: 6 additions & 4 deletions R/velocity.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ velocityDependencies <- function() {
list(
htmlDependency(
"lfx-velocity", "1.0.0",
src = system.file("htmlwidgets/lfx-velocity", package = "leaflet.extras2"),
src = system.file("htmlwidgets/lfx-velocity",
package = "leaflet.extras2"),
script = c(
"leaflet-velocity.js",
"leaflet-velocity-bindings.js"
Expand All @@ -18,8 +19,8 @@ velocityDependencies <- function() {
#' \href{https://github.com/onaci/leaflet-velocity}{leaflet-velocity plugin}
#' @inheritParams leaflet::addMarkers
#' @param content the path or URL to a JSON file representing the velocity data
#' or a data.frame which can be transformed to such a JSON file. Please see the
#' \href{https://github.com/onaci/leaflet-velocity/tree/master/demo}{demo
#' or a data.frame which can be transformed to such a JSON file. Please see
#' the \href{https://github.com/onaci/leaflet-velocity/tree/master/demo}{demo
#' files} for some example data.
#' @param options List of further options. See \code{\link{velocityOptions}}
#' @export
Expand Down Expand Up @@ -72,7 +73,8 @@ addVelocity <- function(map, layerId = NULL, group = NULL,
#' @param velocityScale scale for wind velocity
#' @param colorScale A vector of hex colors or an RGB matrix
#' @param ... Further arguments passed to the Velocity layer and Windy.js.
#' For more information, please visit \href{https://github.com/onaci/leaflet-velocity}{leaflet-velocity plugin}
#' For more information, please visit
#' \href{https://github.com/onaci/leaflet-velocity}{leaflet-velocity plugin}
#' @return A list of further options for \code{addVelocity}
#' @export
#' @family Velocity Functions
Expand Down
4 changes: 3 additions & 1 deletion data-raw/data-raw.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
gibs_layerslink <- paste0(system.file("htmlwidgets/lfx-gibs", package = "leaflet.extras2"), "/gibs_layers_meta.json")
gibs_layerslink <- paste0(
system.file("htmlwidgets/lfx-gibs",
package = "leaflet.extras2"), "/gibs_layers_meta.json")
gibs_layers <- jsonify::from_json(json = gibs_layerslink, simplify = TRUE)
gibs_layers <- data.frame(do.call(rbind, gibs_layers), stringsAsFactors = FALSE)
gibs_layers$title <- as.character(gibs_layers$title)
Expand Down
7 changes: 4 additions & 3 deletions inst/examples/antpath_app.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,19 @@ server <- function(input, output, session) {
label = ~sprintf("Ant-Colony of %s", district),
group = "antgroup",
color = cols,
weight = 2 + (1:nrow(coords))/30,
weight = 2 + (1:nrow(coords)) / 30,
popup = ~FGN,
opacity = 1,
options = antpathOptions(
pulseColor = colorNumeric("Reds",
pulseColor = colorNumeric(
"Reds",
domain = as.numeric(coords$FKN))(as.numeric(coords$FKN)),
delay = 4000,
paused = FALSE,
renderer= JS('L.svg({pane: "my-pane"})'),
reverse = TRUE,
dashArray = c(40, 10),
hardwareAccelerated = T,
hardwareAccelerated = TRUE,
interactive = TRUE,
lineCap = "butt",
lineJoin = "butt",
Expand Down
45 changes: 23 additions & 22 deletions inst/examples/arrowhead_app.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,60 +3,61 @@ library(leaflet)
library(leaflet.extras2)

ui <- fluidPage(
leafletOutput("map", height=800),
leafletOutput("map", height = 800),
actionButton("clear", "Clear Group"),
actionButton("remove", "Remove"),
actionButton("clearArrowhead", "Remove Arrowheads by group"),
actionButton("removeArrowhead", "Remove Arrowheads by layerId's")
actionButton("removeArrowhead", "Remove Arrowheads by layerIds")
)

server <- function(input, output, session) {
output$map <- renderLeaflet({
leaflet() %>%
addTiles() %>%
addLayersControl(overlayGroups = c("blue","red")) %>%
addLayersControl(overlayGroups = c("blue", "red")) %>%
## Blue #############
addArrowhead(data = atlStorms2005[1:10,], color="blue",
group="blue",
addArrowhead(data = atlStorms2005[1:10,], color = "blue",
group = "blue",
options = arrowheadOptions(
yawn = 60,
size = '7%',
frequency = 'endonly',
size = "7%",
frequency = "endonly",
fill = TRUE,
opacity=0.5, stroke=FALSE, fillOpacity=0.4,
opacity = 0.5, stroke = FALSE, fillOpacity = 0.4,
proportionalToTotal = TRUE,
offsets = NULL,
perArrowheadOptions = NULL)) %>%
## Red #############
addArrowhead(data = atlStorms2005[11:20,], color = "red",
addArrowhead(data = atlStorms2005[11:20, ], color = "red",
group = "red",
layerId = paste0("inp",1:10),
layerId = paste0("inp", 1:10),
options = arrowheadOptions(
yawn = 90,
size = '10px',
frequency = 'allvertices',
size = "10px",
frequency = "allvertices",
fill = TRUE,
offsets = NULL,
perArrowheadOptions = NULL)) %>%
## Green #############
addArrowhead(data = atlStorms2005[21,], color = "green", group="green",
addArrowhead(data = atlStorms2005[21, ], color = "green",
group = "green",
options = arrowheadOptions(
size = '10px',
frequency = '50px',
offsets = list('start' = '100m', 'end' = '15px'),
size = "10px",
frequency = "50px",
offsets = list("start" = "100m", "end" = "15px"),
fill = TRUE)) %>%
## Yellow #############
addArrowhead(data = atlStorms2005[22,], color = "yellow",
addArrowhead(data = atlStorms2005[22, ], color = "yellow",
options = arrowheadOptions(
size = "25000m",
frequency = '200000m',
frequency = "200000m",
fill = TRUE)) %>%
## Purple #############
addArrowhead(data = atlStorms2005[24,], color = "purple",
addArrowhead(data = atlStorms2005[24, ], color = "purple",
options = arrowheadOptions(
opacity=1, fillOpacity=1,
opacity = 1, fillOpacity = 1,
frequency = "30px",
size= "20px", fill=TRUE,
size = "20px", fill = TRUE,
perArrowheadOptions = leaflet::JS("(i) => ({
color: `rgba(150, 20, ${0 + 20 * i}, 1)`,
})")))
Expand All @@ -75,7 +76,7 @@ server <- function(input, output, session) {
})
observeEvent(input$removeArrowhead, {
leafletProxy("map") %>%
removeArrowhead(paste0("inp",1:5))
removeArrowhead(paste0("inp", 1:5))
})
}
shinyApp(ui, server)
48 changes: 25 additions & 23 deletions inst/examples/buildings_app.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@ library(sf)
library(leaflet.extras2)
options("shiny.autoreload" = TRUE)

cols <- c("green","orange","red","pink","yellow","blue","lightblue")
darkcols <- c("lightgray","gray","#c49071","#876302","#443408")
cols <- c("green", "orange", "red", "pink", "yellow", "blue", "lightblue")
darkcols <- c("lightgray", "gray", "#c49071", "#876302", "#443408")

## Custom GeoJSON ###########
## Get a Sample Building Dataset from
# https://hub.arcgis.com/datasets/IthacaNY::buildings/explore?location=42.432557%2C-76.486649%2C13.42
geojson <- yyjsonr::read_geojson_file("Buildings_mini.geojson")
geojson$height= sample(seq(50,100,5), nrow(geojson), replace = TRUE)
geojson$color= sample(cols, nrow(geojson), replace = TRUE)
geojson$wallColor= sample(cols, nrow(geojson), replace = TRUE)
geojson$roofColor= sample(darkcols, nrow(geojson), replace = TRUE)
geojson$shape= sample(c("cylinder","sphere",""), nrow(geojson), replace = TRUE)
geojson$roofHeight= geojson$height + sample(seq(1,10,1), nrow(geojson), replace = TRUE)
geojson$roofShape= sample(c("dome","pyramidal", "butterfly","gabled","half-hipped",
"gambrel","onion"), nrow(geojson), replace = TRUE)
geojson$height <- sample(seq(50, 100, 5), nrow(geojson), replace = TRUE)
geojson$color <- sample(cols, nrow(geojson), replace = TRUE)
geojson$wallColor <- sample(cols, nrow(geojson), replace = TRUE)
geojson$roofColor <- sample(darkcols, nrow(geojson), replace = TRUE)
geojson$shape <- sample(c("cylinder", "sphere", ""), nrow(geojson), replace = TRUE)
geojson$roofHeight <- geojson$height + sample(seq(1, 10, 1), nrow(geojson), replace = TRUE)
geojson$roofShape <- sample(c("dome", "pyramidal", "butterfly", "gabled", "half-hipped",
"gambrel", "onion"), nrow(geojson), replace = TRUE)
geojson <- yyjsonr::write_geojson_str(geojson)
class(geojson) <- "json"

Expand All @@ -32,7 +32,7 @@ ui <- fluidPage(
, selectInput("src", label = "Data Source", choices = c("OSM", "GeoJSON"))
, h4("Change the Date and Time-Slider to Adapt the Shadow")
, dateInput("date", "Date")
, sliderInput("time", "Time", 7, max =20, value = 11, step = 1)
, sliderInput("time", "Time", 7, max = 20, value = 11, step = 1)
, h4("Change the Style and the Data")
, actionButton("style", "Update Style")
, actionButton("data", "Update Data")
Expand All @@ -47,7 +47,7 @@ ui <- fluidPage(
## SERVER ###########
server <- function(input, output, session) {
output$map <- renderLeaflet({
m <- leaflet() %>%
m <- leaflet() %>%
addProviderTiles("CartoDB")

if (input$src == "OSM") {
Expand Down Expand Up @@ -78,20 +78,22 @@ server <- function(input, output, session) {
})
observeEvent(input$style, {
leafletProxy("map") %>%
setBuildingStyle(style = list(color = sample(cols, 1),
wallColor = sample(cols, 1),
roofColor = sample(cols, 1),
roofShape = sample(c("dome","pyramidal", "butterfly","gabled","half-hipped",
"gambrel","onion"), 1),
shadows = sample(c(TRUE, FALSE), 1)))
setBuildingStyle(style = list(
color = sample(cols, 1),
wallColor = sample(cols, 1),
roofColor = sample(cols, 1),
roofShape = sample(c("dome", "pyramidal", "butterfly",
"gabled", "half-hipped",
"gambrel", "onion"), 1),
shadows = sample(c(TRUE, FALSE), 1)))
})
observeEvent(input$data, {
geojson <- yyjsonr::read_geojson_file("Buildings_mini.geojson")
filtered <- geojson[sample(1:nrow(geojson), 10, F),]
filtered$height= sample(seq(50,140,5), nrow(filtered), replace = TRUE)
filtered$color= sample(cols, nrow(filtered), replace = TRUE)
filtered$wallColor= sample(cols, nrow(filtered), replace = TRUE)
filtered$roofColor= sample(cols, nrow(filtered), replace = TRUE)
filtered <- geojson[sample(1:nrow(geojson), 10, FALSE),]
filtered$height <- sample(seq(50,140,5), nrow(filtered), replace = TRUE)
filtered$color <- sample(cols, nrow(filtered), replace = TRUE)
filtered$wallColor <- sample(cols, nrow(filtered), replace = TRUE)
filtered$roofColor <- sample(cols, nrow(filtered), replace = TRUE)
filtered <- yyjsonr::write_geojson_str(filtered)
class(filtered) <- "json"

Expand Down
50 changes: 22 additions & 28 deletions inst/examples/clusterCharts_app.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,22 @@ library(leaflet.extras2)
options("shiny.autoreload" = TRUE)


# shipIcon <- leaflet::makeIcon(
# iconUrl = "./icons/Icon5.svg"
# ,className = "lsaicons"
# ,iconWidth = 24, iconHeight = 24, iconAnchorX = 0, iconAnchorY = 0
# )
shipIcon <- iconList(
"Schwer" = makeIcon("./icons/Icon5.svg", iconWidth = 32, iconHeight = 32),
"Mäßig" = makeIcon("./icons/Icon8.svg", iconWidth = 32, iconHeight = 32),
"Leicht" = makeIcon("./icons/Icon25.svg", iconWidth = 32, iconHeight = 32),
"kein Schaden" = makeIcon("./icons/Icon29.svg", iconWidth = 32, iconHeight = 32)
)
# shipIcon <- makeIcon(
# iconUrl = "https://cdn-icons-png.flaticon.com/512/1355/1355883.png",
# iconWidth = 40, iconHeight = 50,
# iconAnchorX = 0, iconAnchorY = 0
# )

data <- sf::st_as_sf(breweries91)
data$categoryfields <- sample(c("Schwer", "Mäßig", "Leicht", "kein Schaden"), size = nrow(data), replace = TRUE)
data$categoryfields <- sample(c("Schwer", "Mäßig", "Leicht", "kein Schaden"),
size = nrow(data), replace = TRUE)
data$label <- paste0(data$brewery, "<br>", data$address)
data$id <- paste0("ID", seq.int(nrow(data)))
data$popup <- paste0("<h6>", data$brewery, "</h6><div>", data$address, "</div>")
data$web <- gsub(">(.*?)<", ">LINK<", data$web)
data$web <- ifelse(is.na(data$web), "", paste0("<div class='markerhtml'>", data$web, "</div>"))
data$web <- ifelse(is.na(data$web), "",
paste0("<div class='markerhtml'>", data$web, "</div>"))
data$tosum <- sample(1:100, nrow(data), replace = TRUE)

ui <- fluidPage(
Expand All @@ -50,14 +42,15 @@ ui <- fluidPage(
}")),
div(class="inputdiv",
div(class="inputs",
selectInput("type", "Plot type", choices = c("bar","horizontal", "pie"), selected = "pie"),
selectInput("type", "Plot type", choices = c("bar","horizontal", "pie"),
selected = "pie"),
numericInput("stroke", "strokeWidth", 1, 1, 10),
numericInput("rmax", "MaxRadius", 50, 1, 150),
numericInput("innerRadius", "InnerRadius", 10, 1, 100),
numericInput("width", "Width", 50, 1, 150),
numericInput("height", "Height", 50, 1, 150),
selectInput("labelBackground", "labelBackground", choices = c(T,F)),
selectInput("sortTitlebyCount", "sortTitlebyCount", choices = c(T,F)),
selectInput("labelBackground", "labelBackground", choices = c(TRUE, FALSE)),
selectInput("sortTitlebyCount", "sortTitlebyCount", choices = c(TRUE, FALSE)),
numericInput("labelOpacity", "labelOpacity", 0.5, 0, 1, step = 0.1),
)),
leafletOutput("map", height = 650),
Expand All @@ -76,19 +69,20 @@ server <- function(input, output, session) {
leaflet::addLayersControl(overlayGroups = c("clustermarkers")) %>%
# addCircleMarkers(data = data, group = "normalcircles", clusterOptions = markerClusterOptions()) %>%
addClusterCharts(data = data
, options = clusterchartOptions(rmax = input$rmax,
size = c(100,40),
# size=40,
width = input$width,
height = input$height,
strokeWidth = input$stroke,
labelBackground = as.logical(input$labelBackground),
# labelFill = "red",
# labelStroke = "green",
labelColor = "blue",
labelOpacity = input$labelOpacity,
innerRadius = input$innerRadius,
sortTitlebyCount = as.logical(input$sortTitlebyCount))
, options = clusterchartOptions(
rmax = input$rmax,
size = c(100,40),
# size=40,
width = input$width,
height = input$height,
strokeWidth = input$stroke,
labelBackground = as.logical(input$labelBackground),
# labelFill = "red",
# labelStroke = "green",
labelColor = "blue",
labelOpacity = input$labelOpacity,
innerRadius = input$innerRadius,
sortTitlebyCount = as.logical(input$sortTitlebyCount))
# , type = "bar"
# , type = "horizontal"
, type = input$type
Expand Down
Loading

0 comments on commit 9fd266a

Please sign in to comment.