Skip to content

Commit

Permalink
add option to load and render a tif raster via input file
Browse files Browse the repository at this point in the history
  • Loading branch information
osalamon committed Oct 18, 2024
1 parent c556765 commit aa2df58
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 27 deletions.
7 changes: 5 additions & 2 deletions app/view/disease_outbreaks/disease_app/disease_app.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
box::use(
shiny[NS, tagList, moduleServer, tags, reactiveVal, reactive, observeEvent],
shiny[NS, tagList, moduleServer, tags, reactiveVal, reactive, observeEvent, req],
bslib[layout_column_wrap],
htmltools[css],
)
Expand Down Expand Up @@ -39,6 +39,8 @@ disease_app_server <- function(id, tab_disease_selected) {
map <- reactiveVal()
leaflet_map <- reactiveVal()

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

observeEvent(tab_disease_selected(),
ignoreInit = TRUE,
{
Expand All @@ -56,7 +58,8 @@ disease_app_server <- function(id, tab_disease_selected) {
# MAP itself ----
disease_map_server(
"disease_map",
leaflet_map = leaflet_map
leaflet_map = leaflet_map,
new_tif_upload
)
}
)
Expand Down
15 changes: 14 additions & 1 deletion app/view/disease_outbreaks/disease_app/disease_map.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ disease_map_ui <- function(id, i18n) {
}

#' @export
disease_map_server <- function(id, leaflet_map) {
disease_map_server <- function(id, leaflet_map, new_tif_upload) {
moduleServer(id, function(input, output, session) {
ns <- session$ns
# Define waiter ----
Expand All @@ -55,5 +55,18 @@ disease_map_server <- function(id, leaflet_map) {
w$hide()
})

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

req(new_tif_rast)
leafletProxy("map_output") |>
addRasterImage(
new_tif_rast,
opacity = 1,
project = FALSE,
group = "File upload"
)
})
})
}
32 changes: 8 additions & 24 deletions app/view/disease_outbreaks/disease_app/disease_select.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
box::use(
shiny[moduleServer, NS, tagList, checkboxInput, bootstrapPage, tags, observeEvent, reactiveVal, reactive, actionButton],
shiny[moduleServer, NS, tagList, checkboxInput, bootstrapPage, tags, observeEvent, reactiveVal, reactive, actionButton, fileInput, req, validate, need],
bslib[card, card_header, card_body],
leaflet[clearImages, leafletProxy]
)

box::use(
# app/logic/disease_outbreaks/disease_leaflet_map[remove_map_layer]
leaflet[clearImages, leafletProxy],
)

#' @export
Expand All @@ -23,7 +19,9 @@ disease_select_ui <- function(id, theme, i18n) {
"File input"
)
),
card_body(),
card_body(
fileInput(ns("tif_file"), "Choose .tif file", accept = ".tif"),
),
)
)
}
Expand All @@ -34,26 +32,12 @@ disease_select_server <- function(id, tab_disease_selected) {
ns <- session$ns
out <- reactiveVal(NULL)

events <- reactive({
tab_disease_selected()
input$mosaic_final
input$outfirst_infection
})

observeEvent(
events(),
input$tif_file,
ignoreInit = TRUE,
ignoreNULL = TRUE,
{
if (input$mosaic_final == TRUE) {
"Mosaic_final" |>
out()
}

if (input$outfirst_infection == TRUE) {
"outfirst_infection" |>
out()
}
{
out(input$tif_file$datapath)
})

reactive(out())
Expand Down

0 comments on commit aa2df58

Please sign in to comment.