-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #109 from BioDT/95-prepare-wild-boar-disease
Prepare wild boar disease's main pDT page
- Loading branch information
Showing
8 changed files
with
322 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
box::use( | ||
terra[rast, project], | ||
leaflet[tileOptions, leaflet, addTiles, addRasterImage, setView, addLayersControl, layersControlOptions, addControl, getMapData, addProviderTiles], | ||
) | ||
|
||
#' @export | ||
read_and_project_raster <- function(map_full_path) { | ||
map_raster <- rast(map_full_path) |> project("epsg:3857") | ||
} | ||
|
||
#' @export | ||
disease_leaflet_map_basic <- function(map_raster, | ||
add_control = TRUE, | ||
main_map_features = TRUE) { | ||
leaflet_map <- leaflet() |> | ||
addTiles(group = "Default layer (OpenStreetMap)") |> | ||
setView( | ||
lng = 12.3601, | ||
lat = 51.3402, | ||
zoom = 5 | ||
) |> | ||
addRasterImage( | ||
map_raster, | ||
opacity = 0.5, | ||
project = FALSE, | ||
options = tileOptions(zIndex = 100), | ||
group = "Input layer" | ||
) |> | ||
addLayersControl( | ||
baseGroups = c( | ||
"Default layer (OpenStreetMap)" | ||
), | ||
overlayGroups = c("Input layer"), | ||
options = layersControlOptions(collapsed = FALSE) | ||
) | ||
|
||
return(leaflet_map) | ||
} | ||
|
||
# #' @export | ||
# disease_leaflet_with_output_layer <- function(map_output_id, input_raster, output_raster) { | ||
|
||
|
||
# leafletProxy(map_output_id) |> # hint: leafletProxy, removeImage, addRasterLegend, addLegend, | ||
# clearImages() |> | ||
# clearControls() |> | ||
# addRasterImage( | ||
# input_raster, | ||
# opacity = 0.5, | ||
# project = FALSE, | ||
# options = tileOptions(zIndex = 100), | ||
# group = "Input layer", | ||
# layerId = "inputLayer" | ||
# ) |> | ||
# addRasterImage( | ||
# output_raster, | ||
# opacity = 0.5, | ||
# project = FALSE, | ||
# options = tileOptions(zIndex = 101), | ||
# group = "Output layer", | ||
# layerId = "outputLayer" | ||
# ) |> | ||
# addLayersControl( | ||
# overlayGroups = c("Input layer", "Output layer"), | ||
# options = layersControlOptions(collapsed = FALSE) | ||
# ) | ||
# } | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
app/view/disease_outbreaks/disease_app/disease_choose_file.R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
box::use( | ||
shiny[moduleServer, NS, bootstrapPage, tags, observeEvent, reactiveVal, reactive, fileInput], | ||
bslib[card, card_header, card_body], | ||
) | ||
|
||
#' @export | ||
disease_choose_file_ui <- function(id, theme, i18n) { | ||
ns <- NS(id) | ||
bootstrapPage( | ||
theme = theme, | ||
card( | ||
class = "me-md-3 card-shadow overflow-hidden mt-2", | ||
title = "select_map", | ||
full_screen = FALSE, | ||
card_header( | ||
tags$h2( | ||
class = "card_title", | ||
"Upload a file with raster" | ||
) | ||
), | ||
card_body( | ||
fileInput(ns("tif_file"), "Choose .tif file", accept = ".tif"), | ||
), | ||
) | ||
) | ||
} | ||
|
||
#' @export | ||
disease_choose_file_server <- function(id, tab_disease_selected) { | ||
moduleServer(id, function(input, output, session) { | ||
ns <- session$ns | ||
out <- reactiveVal(NULL) | ||
|
||
observeEvent( | ||
input$tif_file, | ||
ignoreInit = TRUE, | ||
ignoreNULL = TRUE, | ||
{ | ||
out(input$tif_file$datapath) | ||
} | ||
) | ||
|
||
reactive(out()) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
box::use( | ||
shiny[NS, moduleServer, tags, observeEvent, req], | ||
bslib[card, card_header, card_body], | ||
leaflet[leafletOutput, renderLeaflet, leafletProxy, addRasterImage, addLayersControl, layersControlOptions, tileOptions, clearControls, clearImages], | ||
) | ||
|
||
box::use( | ||
app / logic / disease_outbreaks / disease_leaflet_map[read_and_project_raster] | ||
) | ||
|
||
#' @export | ||
disease_map_ui <- function(id, i18n) { | ||
ns <- NS(id) | ||
card( | ||
id = ns("map_wrapper"), | ||
class = "ms-md-3 card-shadow mt-2", | ||
full_screen = TRUE, | ||
card_header( | ||
tags$h2( | ||
class = "card_title", | ||
i18n$translate("Map") | ||
) | ||
), | ||
card_body( | ||
leafletOutput( | ||
ns("map_output") | ||
), | ||
), | ||
) | ||
} | ||
|
||
#' @export | ||
disease_map_server <- function(id, map_original, leaflet_map, new_tif_upload) { | ||
moduleServer(id, function(input, output, session) { | ||
ns <- session$ns | ||
|
||
observeEvent(leaflet_map(), { | ||
req(leaflet_map()) | ||
output_map <- leaflet_map() | ||
output$map_output <- renderLeaflet(output_map) | ||
}) | ||
|
||
observeEvent(new_tif_upload(), { | ||
new_tif_raster <- new_tif_upload() |> | ||
read_and_project_raster() | ||
|
||
req(new_tif_raster) | ||
leafletProxy("map_output") |> | ||
clearImages() |> | ||
clearControls() |> | ||
addRasterImage( | ||
map_original(), | ||
opacity = 0.5, | ||
project = FALSE, | ||
options = tileOptions(zIndex = 100), | ||
group = "Input layer", | ||
layerId = "inputLayer" | ||
) |> | ||
addRasterImage( | ||
new_tif_raster, | ||
opacity = 0.5, | ||
project = FALSE, | ||
options = tileOptions(zIndex = 101), | ||
group = "Output layer", | ||
layerId = "outputLayer" | ||
) |> | ||
addLayersControl( | ||
overlayGroups = c("Input layer", "Output layer"), | ||
options = layersControlOptions(collapsed = FALSE) | ||
) | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
box::use( | ||
shiny[moduleServer, NS, tagList, div, column, tags, fluidRow, icon], | ||
) | ||
|
||
#' @export | ||
disease_contributors_ui <- function(id, i18n) { # nolint | ||
ns <- NS(id) | ||
fluidRow( | ||
class = "align-items-center justify-content-center m-0 p-0", | ||
style = "overflow-x: hidden", | ||
column( | ||
width = 6, | ||
class = "col-sm-12 col-lg-6", | ||
style = "height: 100vh;", | ||
tags$div( | ||
class = "col-sm-10 offset-sm-1 text-center mt-5", | ||
tags$h2(i18n$translate("CONTRIBUTORS"), | ||
style = "greeting display-4 font-weight-bold" | ||
), | ||
tags$p("TO BE ADDED"), | ||
) | ||
), | ||
column( | ||
width = 6, | ||
style = "height: 100vh;", | ||
class = "d-none d-lg-block m-0 p-0", | ||
tags$div( | ||
tags$img( | ||
class = "info-picture", | ||
src = "static/img/Alexis-Lours-Sus-scrofa-Linnaeus.gif", | ||
alt = "Video of wild boar pack", | ||
) | ||
) | ||
) | ||
) | ||
} | ||
|
||
#' @export | ||
disease_contributors_server <- function(id, r) { # nolint | ||
moduleServer(id, function(input, output, session) { | ||
ns <- session$ns | ||
}) | ||
} |
Oops, something went wrong.