Skip to content

Commit

Permalink
lint app with new {rhino} and {box.linters}
Browse files Browse the repository at this point in the history
  • Loading branch information
RWParsons committed Jun 15, 2024
1 parent 782e7d0 commit fd6ea0f
Show file tree
Hide file tree
Showing 19 changed files with 137 additions and 111 deletions.
8 changes: 2 additions & 6 deletions app/.lintr
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
linters:
linters_with_defaults(
line_length_linter = line_length_linter(100),
box_func_import_count_linter = rhino::box_func_import_count_linter(),
box_separate_calls_linter = rhino::box_separate_calls_linter(),
box_trailing_commas_linter = rhino::box_trailing_commas_linter(),
box_universal_import_linter = rhino::box_universal_import_linter(),
object_usage_linter = NULL # Does not work with `box::use()`.
defaults = box.linters::box_default_linters
)
encoding: "UTF-8"
8 changes: 7 additions & 1 deletion app/app/logic/constants.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ box::use(
)

#' @export
all_base_layers <- c("Towns", "Acute centres", "Rehab centres", "Aeromedical bases", "QAS response locations")
all_base_layers <- c(
"Towns",
"Acute centres",
"Rehab centres",
"Aeromedical bases",
"QAS response locations"
)

#' @export
default_base_layers <- c("Towns", "Acute centres", "Rehab centres")
Expand Down
36 changes: 12 additions & 24 deletions app/app/logic/load_shapes.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
box::use(
purrr,
sf,
tidyterra,
)

Expand All @@ -12,37 +11,26 @@ box::use(
state_boundary <- readRDS(file.path(constants$data_dir, "state_boundary.rds"))

#' @export
stacked_sa1_sa2_polygon_geom <- readRDS(file.path(constants$data_dir, "stacked_SA1_and_SA2_polygons_geom.rds"))
stacked_sa1_sa2_polygon_geom <- readRDS(file.path(
constants$data_dir,
"stacked_SA1_and_SA2_polygons_geom.rds"
))

#' @export
stacked_sa1_sa2_linestring_geom <- readRDS(file.path(constants$data_dir, "stacked_SA1_and_SA2_linestrings_geom.rds"))
stacked_sa1_sa2_linestring_geom <- readRDS(file.path(
constants$data_dir,
"stacked_SA1_and_SA2_linestrings_geom.rds"
))

#' @export
stacked_sa1_sa2_data <- readRDS(file.path(constants$data_dir, "stacked_sa1_sa2_data.rds"))
stacked_sa1_sa2_data <- readRDS(file.path(
constants$data_dir,
"stacked_sa1_sa2_data.rds"
))

#' @export
raster_layers <- readRDS(file.path(constants$data_dir, "raster_points.rds")) |>
purrr$map(~ tidyterra$as_spatraster(.x, crs = 4326))

#' @export
l_markers <- readRDS(file.path(constants$data_dir, "l_markers.rds"))

# old pipeline outputs that would have been useful if taking the updating-shape-aes approach
#' @export
# sa1_polygon <- readRDS(file.path(analyses_output_dir, "sa1_polygon.rds"))

#' @export
# sa1_linestring <- readRDS(file.path(analyses_output_dir, "sa1_linestring.rds"))

#' @export
# sa2_linestring <- readRDS(file.path(analyses_output_dir, "sa2_linestring.rds"))

#' @export
# sa1_sa2_code_lkp <- readRDS(file.path(analyses_output_dir, "sa1_sa2_code_lkp.rds"))

#' @export
# sa_code_layerid_lkp <- readRDS(file.path(analyses_output_dir, "sa_code_layerid_lkp.rds"))

# TODO: later....
# create a lookup between all filters and the layerids above so that layer ids
# can easily be selected based on selected filters
32 changes: 24 additions & 8 deletions app/app/logic/scales_and_palettes.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
box::use(
dplyr,
leaflet,
withr,
)
Expand All @@ -16,31 +15,43 @@ scale_fxs <- readRDS(file.path(constants$data_dir, "scale_fxs.rds"))
get_itraqi_index <- scale_fxs$itraqi_index

#' @export
seifa_scale_to_text <- function(x) withr$with_package("dplyr", scale_fxs$seifa_scale_to_text(x))
seifa_scale_to_text <- function(x) {
withr$with_package("dplyr", scale_fxs$seifa_scale_to_text(x))
}

#' @export
seifa_text_to_value <- function(x) withr$with_package("dplyr", scale_fxs$seifa_text_to_value(x))
seifa_text_to_value <- function(x) {
withr$with_package("dplyr", scale_fxs$seifa_text_to_value(x))
}

#' @export
seifa_text_choices <- c(seifa_scale_to_text(1:5), "NA")

#' @export
ra_scale_to_text <- function(x) withr$with_package("dplyr", scale_fxs$ra_scale_to_text(x))
ra_scale_to_text <- function(x) {
withr$with_package("dplyr", scale_fxs$ra_scale_to_text(x))
}

#' @export
ra_text_to_value <- function(x) withr$with_package("dplyr", scale_fxs$ra_text_to_value(x))
ra_text_to_value <- function(x) {
withr$with_package("dplyr", scale_fxs$ra_text_to_value(x))
}

#' @export
ra_text_choices <- ra_scale_to_text(0:4)

#' @export
pal_mins <- function(x) withr$with_package("dplyr", palette_list$palNum(x))
pal_mins <- function(x) {
withr$with_package("dplyr", palette_list$palNum(x))
}

#' @export
bins_mins <- palette_list$bins_mins

#' @export
pal_hours <- function(x) withr$with_package("dplyr", palette_list$palNum_hours(x))
pal_hours <- function(x) {
withr$with_package("dplyr", palette_list$palNum_hours(x))
}

#' @export
pal_index <- palette_list$paliTRAQI
Expand All @@ -49,7 +60,12 @@ pal_index <- palette_list$paliTRAQI
iTRAQI_levels <- levels(palette_list$bins_index)

#' @export
pal_aria <- leaflet$colorFactor("Greens", levels = ra_text_choices, ordered = TRUE, reverse = TRUE)
pal_aria <- leaflet$colorFactor(
"Greens",
levels = ra_text_choices,
ordered = TRUE,
reverse = TRUE
)

#' @export
get_palette <- function(outcome) {
Expand Down
1 change: 0 additions & 1 deletion app/app/logic/wrangle_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ box::use(
)

box::use(
app / logic / constants,
app / logic / load_shapes,
app / logic / scales_and_palettes,
app / logic / utils,
Expand Down
40 changes: 32 additions & 8 deletions app/app/mapping/make_map.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
box::use(
leaflet,
leafgl,
sf,
)

box::use(
Expand Down Expand Up @@ -83,24 +82,49 @@ make_base_map <- function(show_default_markers = TRUE) {

#' @export
add_map_content <- function(proxy_map, map_content) {
for (sh_idx in 1:length(map_content)) {
for (sh_idx in seq_along(length(map_content))) {
sh <- map_content[[sh_idx]]
if (sh$type == "polygon") {
proxy_map <- proxy_map |>
leafgl$addGlPolygons(data = sh$polygon, layerId = sh$layerid, pane = "layers", group = "layers")
leafgl$addGlPolygons(
data = sh$polygon,
layerId = sh$layerid,
pane = "layers",
group = "layers"
)
}

if (sh$type == "linestring") {
proxy_map <- proxy_map |>
leafgl$addGlPolylines(data = sh$linestring, layerId = sh$layerid, group = "layers")
leafgl$addGlPolylines(
data = sh$linestring,
layerId = sh$layerid,
group = "layers"
)
}
}
}


centre_icons <- leaflet$iconList(
acute = leaflet$makeIcon(iconUrl = "static/images/acute-centre.png", iconWidth = 50, iconHeight = 50),
rehab = leaflet$makeIcon(iconUrl = "static/images/rehab-centre.png", iconWidth = 40, iconHeight = 40),
rsq = leaflet$makeIcon(iconUrl = "static/images/rsq.png", iconWidth = 50, iconHeight = 30),
qas = leaflet$makeIcon(iconUrl = "static/images/qas.png", iconWidth = 10, iconHeight = 10)
acute = leaflet$makeIcon(
iconUrl = "static/images/acute-centre.png",
iconWidth = 50,
iconHeight = 50
),
rehab = leaflet$makeIcon(
iconUrl = "static/images/rehab-centre.png",
iconWidth = 40,
iconHeight = 40
),
rsq = leaflet$makeIcon(
iconUrl = "static/images/rsq.png",
iconWidth = 50,
iconHeight = 30
),
qas = leaflet$makeIcon(
iconUrl = "static/images/qas.png",
iconWidth = 10,
iconHeight = 10
)
)
8 changes: 4 additions & 4 deletions app/app/mapping/prediction_markers.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@ box::use(

#' @export
add_prediction_marker <- function(proxy_map, map_click) {
# browser()
lat <- map_click$lat
lng <- map_click$lng

if (!is_point_in_qld(lat = lat, lng = lng)) {
return()
}
# add marker and popup

acute_pred <- get_pred_time(lng = lng, lat = lat, care_type = "acute")$pred
rehab_pred <- get_pred_time(lng = lng, lat = lat, care_type = "rehab")$pred

Expand All @@ -50,7 +48,9 @@ add_prediction_marker <- function(proxy_map, map_click) {
layerId = "map_click_marker"
)

shinyjs$runjs(sprintf("setTimeout(() => open_popup('%s'), 500)", "map_click_marker"))
shinyjs$runjs(
sprintf("setTimeout(() => open_popup('%s'), 500)", "map_click_marker")
)
}


Expand Down Expand Up @@ -96,7 +96,7 @@ prediction_marker_tags <- function() {
paste(
"var mapsPlaceholder = [];",
"L.Map.addInitHook(function () {",
" mapsPlaceholder.push(this); // Use whatever global scope variable you like.",
" mapsPlaceholder.push(this);",
"});",
sep = "\n"
)
Expand Down
2 changes: 0 additions & 2 deletions app/app/mapping/ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ box::use(
leaflet,
)



#' @export
mapOutput <- function(id) {
leaflet$leafletOutput(id, width = "100%", height = "100%")
Expand Down
6 changes: 4 additions & 2 deletions app/app/mapping/update_legend.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
box::use(
leaflegend,
leaflet,
shiny,
stringr,
)

Expand Down Expand Up @@ -41,7 +40,10 @@ add_aria_legend <- \(map) {
map = map,
position = legend_position,
pal = scales_and_palettes$pal_aria,
values = factor(scales_and_palettes$ra_text_choices, levels = scales_and_palettes$ra_text_choices),
values = factor(
scales_and_palettes$ra_text_choices,
levels = scales_and_palettes$ra_text_choices
),
layerId = "ariaLegend"
)
}
Expand Down
25 changes: 18 additions & 7 deletions app/app/mapping/update_map_content.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ box::use(
leafgl,
sf,
stringr,
withr,
)


Expand Down Expand Up @@ -32,7 +31,10 @@ add_clicked_point <- function(proxy_map, d_clicked) {

if (nrow(d_clicked_top) > 0) {
d_popup_add <- load_shapes$stacked_sa1_sa2_polygon_geom |>
dplyr$inner_join(dplyr$select(d_clicked_top, CODE, selected_popup), by = "CODE")
dplyr$inner_join(
dplyr$select(d_clicked_top, CODE, selected_popup),
by = "CODE"
)

suppressWarnings({
d_coords <- d_popup_add |>
Expand Down Expand Up @@ -82,16 +84,27 @@ update_map_markers <- function(proxy_map, markers) {
}

#' @export
update_map_shapes <- function(proxy_map, d_selection, selected_layer, r_layers) {
update_map_shapes <- function(proxy_map,
d_selection,
selected_layer,
r_layers) {
layer_type <- utils$get_layer_type(selected_layer)
selected_layer <- utils$get_standard_layer_name(selected_layer)

if (layer_type == "none") {
show_nothing(proxy_map = proxy_map, r_layers = r_layers)
} else if (layer_type == "polygon") {
show_polygon(proxy_map = proxy_map, d_selection = d_selection, r_layers = r_layers)
show_polygon(
proxy_map = proxy_map,
d_selection = d_selection,
r_layers = r_layers
)
} else if (layer_type == "raster") {
show_raster(proxy_map = proxy_map, selected_layer = selected_layer, r_layers = r_layers)
show_raster(
proxy_map = proxy_map,
selected_layer = selected_layer,
r_layers = r_layers
)
}

update_legend$update_legend(
Expand Down Expand Up @@ -152,8 +165,6 @@ show_polygon <- function(proxy_map, d_selection, r_layers) {

fcolor_palette <- scales_and_palettes$get_palette(d_selection$outcome)

# browser()

proxy_map |> leaflet$hideGroup(grp_add)

if (nrow(poly_add) > 1) {
Expand Down
17 changes: 4 additions & 13 deletions app/app/mapping/update_tour_map.R
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
box::use(
dplyr,
leaflet,
leafgl,
sf,
stringr,
withr,
)


box::use(
app / logic / constants,
app / logic / load_shapes,
app / logic / scales_and_palettes,
app / logic / wrangle_data,
app / mapping / update_map_content,
Expand All @@ -19,13 +12,11 @@ box::use(

#' @export
show_tour <- function(proxy_map, tab, map_content, r_layers) {
# TODO: trigger changes to map (via calls to update_map_content module mostly)
# browser()

print(tab)
print(map_content)
# update markers
update_map_content$update_map_markers(proxy_map = proxy_map, markers = map_content)
update_map_content$update_map_markers(
proxy_map = proxy_map,
markers = map_content
)

selected_layer <- get_shapes_from_map_content(map_content)

Expand Down
5 changes: 0 additions & 5 deletions app/app/view/information/page.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
box::use(
bslib,
shiny,
shinyWidgets,
)

box::use(
app / logic / constants,
)


Expand Down
Loading

0 comments on commit fd6ea0f

Please sign in to comment.