Skip to content

Commit

Permalink
codebase polishing: formatter, beter naming etc
Browse files Browse the repository at this point in the history
  • Loading branch information
osalamon committed Oct 22, 2024
1 parent d8c589a commit ff2f5b2
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 38 deletions.
7 changes: 4 additions & 3 deletions app/logic/disease_outbreaks/disease_leaflet_map.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
box::use(
terra[rast, project],
leaflet[tileOptions, leaflet, addTiles, addRasterImage, setView, leafletProxy, removeImage, addRasterLegend, addLegend, addLayersControl],
leaflet[tileOptions, leaflet, addTiles, addRasterImage, setView, addLayersControl, layersControlOptions],
)

#' @export
Expand All @@ -17,7 +17,7 @@ disease_leaflet_map <- function(map_raster,
setView(
lng = 12.3601,
lat = 51.3402,
zoom = 4
zoom = 5
) |>
addRasterImage(
map_raster,
Expand All @@ -27,7 +27,8 @@ disease_leaflet_map <- function(map_raster,
group = "Input layer"
) |>
addLayersControl(
overlayGroups = c("Input layer")
overlayGroups = c("Input layer"),
options = layersControlOptions(collapsed = FALSE)
)

return(leaflet_map)
Expand Down
28 changes: 13 additions & 15 deletions app/view/disease_outbreaks/disease_app/disease_app.R
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
box::use(
shiny[NS, tagList, moduleServer, tags, reactiveVal, reactive, observeEvent, req],
shiny[NS, tagList, moduleServer, tags, reactiveVal, observeEvent],
bslib[layout_column_wrap],
htmltools[css],
waiter[Waiter],
app/logic/waiter[waiter_text],
)

box::use(
app/view/disease_outbreaks/disease_app/disease_map[disease_map_ui, disease_map_server],
app/view/disease_outbreaks/disease_app/disease_select[disease_select_ui, disease_select_server],
app/logic/disease_outbreaks/disease_leaflet_map[read_and_project_raster, disease_leaflet_map]
app / view / disease_outbreaks / disease_app / disease_map[disease_map_ui, disease_map_server],
app / view / disease_outbreaks / disease_app / disease_choose_file[disease_choose_file_ui, disease_choose_file_server],
app / logic / disease_outbreaks / disease_leaflet_map[read_and_project_raster, disease_leaflet_map],
app / logic / waiter[waiter_text],
)


Expand All @@ -24,7 +24,7 @@ disease_app_ui <- function(id, i18n) {
disease_map_ui(
ns("disease_map"), i18n
),
disease_select_ui(
disease_choose_file_ui(
ns("disease_select"), i18n
),
),
Expand All @@ -35,26 +35,25 @@ disease_app_ui <- function(id, i18n) {
#' @export
disease_app_server <- function(id, tab_disease_selected) {
moduleServer(id, function(input, output, session) {

# Define waiter ----
msg <- waiter_text(message = tags$h3("Loading data...",
style = "color: #414f2f;"
))
w <- Waiter$new(
html = msg,
color = "rgba(256,256,256,0.9)"
)
)

ns <- session$ns
# Variables ----
map <- reactiveVal()
leaflet_map <- reactiveVal()

new_tif_upload <- disease_select_server("disease_select", tab_disease_selected())
new_tif_upload <- disease_choose_file_server("disease_select", tab_disease_selected())

observeEvent(tab_disease_selected(),
ignoreInit = TRUE,
{
{
w$show()

"app/data/disease_outbreak/Mosaic_final.tif" |>
Expand All @@ -65,19 +64,18 @@ disease_app_server <- function(id, tab_disease_selected) {
disease_leaflet_map(
add_control = TRUE,
main_map_features = TRUE
) |>
) |>
leaflet_map()

w$hide()

# MAP itself ----
disease_map_server(
"disease_map",
leaflet_map = leaflet_map,
new_tif_upload
)
)
}
)

})
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
box::use(
shiny[moduleServer, NS, tagList, checkboxInput, bootstrapPage, tags, observeEvent, reactiveVal, reactive, actionButton, fileInput, req, validate, need],
shiny[moduleServer, NS, bootstrapPage, tags, observeEvent, reactiveVal, reactive, fileInput],
bslib[card, card_header, card_body],
leaflet[clearImages, leafletProxy],
)

#' @export
disease_select_ui <- function(id, theme, i18n) {
disease_choose_file_ui <- function(id, theme, i18n) {
ns <- NS(id)
bootstrapPage(
theme = theme,
Expand All @@ -27,7 +26,7 @@ disease_select_ui <- function(id, theme, i18n) {
}

#' @export
disease_select_server <- function(id, tab_disease_selected) {
disease_choose_file_server <- function(id, tab_disease_selected) {
moduleServer(id, function(input, output, session) {
ns <- session$ns
out <- reactiveVal(NULL)
Expand All @@ -36,9 +35,10 @@ disease_select_server <- function(id, tab_disease_selected) {
input$tif_file,
ignoreInit = TRUE,
ignoreNULL = TRUE,
{
out(input$tif_file$datapath)
})
{
out(input$tif_file$datapath)
}
)

reactive(out())
})
Expand Down
25 changes: 12 additions & 13 deletions app/view/disease_outbreaks/disease_app/disease_map.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
box::use(
shiny[NS, moduleServer, tags, observeEvent, reactive, actionButton, reactiveVal, checkboxInput, updateCheckboxInput, req],
shiny[NS, moduleServer, tags, observeEvent, req],
bslib[card, card_header, card_body],
leaflet[setView, leaflet, leafletOptions, leafletOutput, renderLeaflet, addTiles, leafletProxy, addRasterImage, clearImages],
terra[rast, project],
leaflet[leafletOutput, renderLeaflet, leafletProxy, addRasterImage],
)

box::use(
app/logic/disease_outbreaks/disease_leaflet_map[read_and_project_raster, disease_leaflet_map]
app / logic / disease_outbreaks / disease_leaflet_map[read_and_project_raster]
)

#' @export
Expand Down Expand Up @@ -36,23 +35,23 @@ disease_map_server <- function(id, leaflet_map, new_tif_upload) {
ns <- session$ns

observeEvent(leaflet_map(), {
req(leaflet_map())
req(leaflet_map())
output_map <- leaflet_map()
output$map_output <- renderLeaflet(output_map)
})

observeEvent(new_tif_upload(), {
new_tif_rast <- new_tif_upload() |>
read_and_project_raster()
read_and_project_raster()

req(new_tif_rast)
leafletProxy("map_output") |>
leafletProxy("map_output") |> # hint: leafletProxy, removeImage, addRasterLegend, addLegend,
addRasterImage(
new_tif_rast,
opacity = 1,
project = FALSE,
group = "File upload"
)
new_tif_rast,
opacity = 1,
project = FALSE,
group = "File upload"
)
})
})
}

0 comments on commit ff2f5b2

Please sign in to comment.