Skip to content

Commit

Permalink
make selectInput working, fix error in outbreaks logic leaflet map fn
Browse files Browse the repository at this point in the history
  • Loading branch information
osalamon committed Sep 23, 2024
1 parent 2753aed commit 24ae9fb
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 17 deletions.
2 changes: 1 addition & 1 deletion app/logic/disease_outbreaks/disease_leaflet_map.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ disease_outbreak_leaflet_map <- function(id, tif_map, tif_map_path, tif_map_repr

# load tif raster, hardcoded for prototype (terra)
tif_map_path() |>
read_disease_outbreak_raster |>
read_disease_outbreak_raster() |>
tif_map()

# project to right CRS (terra)
Expand Down
10 changes: 5 additions & 5 deletions app/view/disease_outbreaks/disease_app/disease_app.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ disease_app_server <- function(id, r) {
ns <- session$ns

# Variables ----
tif_map <- reactiveVal()
tif_map_path <- reactiveVal()
tif_map <- reactiveVal(NULL)
tif_map_path <- reactiveVal(NULL)

# selection of raster map
tif_map <- disease_select_server("disease_select")
print(tif_map)
disease_select_server("disease_select")
# print(tif_map_name)

# MAP itself ----
disease_map_server("disease_map", tif_map())
disease_map_server("disease_map", map_selected = tif_map())
})
}
11 changes: 7 additions & 4 deletions app/view/disease_outbreaks/disease_app/disease_map.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
box::use(
shiny[NS, moduleServer, tags, observeEvent],
shiny[NS, moduleServer, tags, observeEvent, reactive],
bslib[card, card_header, card_body],
leaflet[setView, leaflet, leafletOptions, leafletOutput, renderLeaflet, addTiles],
)

box::use(
app/logic/honeybee/honeybee_beekeeper_map[read_honeybee_tif, honeybee_leaflet_map]
app/logic/disease_outbreaks/disease_leaflet_map[read_disease_outbreak_raster, make_full_tif_map_path, disease_outbreak_leaflet_map]
)

#' @export
Expand Down Expand Up @@ -34,8 +34,11 @@ disease_map_server <- function(id, map, map_selected) {
moduleServer(id, function(input, output, session) {
ns <- session$ns

observeEvent(map_selected(), {

map <- reactive(map_selected)


observeEvent(map(), {
print(map())
})

})
Expand Down
17 changes: 10 additions & 7 deletions app/view/disease_outbreaks/disease_app/disease_select.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ disease_select_ui <- function(id, theme, i18n) {
),
card_body(
selectInput(
"disease_map_select",
ns("disease_map_select"),
label = "Select disease map:",
choices = c("Mosaic_final", "outfirst_infection"),
multiple = FALSE
Expand All @@ -31,18 +31,21 @@ disease_select_ui <- function(id, theme, i18n) {
}

#' @export
disease_select_server <- function(id) {
disease_select_server <- function(id, map) {
moduleServer(id, function(input, output, session) {
ns <- session$ns

out <- reactiveVal()

observeEvent(input$disease_map_select, {
observeEvent(
input$disease_map_select,
ignoreInit = TRUE,
ignoreNULL = TRUE,
{
print(input$disease_map_select)

out <- input$disease_map_select
})

reactive(out())
reactive({
input$disease_map_select
})
})
}

0 comments on commit 24ae9fb

Please sign in to comment.