From b753e5d36880608384ff9386819f501cb6ad15fd Mon Sep 17 00:00:00 2001 From: Antonia Runge Date: Mon, 19 Dec 2022 20:51:22 +0100 Subject: [PATCH 1/6] rename param --- R/02-plotExport.R | 11 ++++++----- R/03-modelResults3D.R | 3 ++- R/03-modelResults3DKernel.R | 3 ++- man/getHrefTag.Rd | 14 ++++++++++++++ 4 files changed, 24 insertions(+), 7 deletions(-) create mode 100644 man/getHrefTag.Rd diff --git a/R/02-plotExport.R b/R/02-plotExport.R index 09579d67..797a3e7f 100644 --- a/R/02-plotExport.R +++ b/R/02-plotExport.R @@ -7,10 +7,11 @@ plotExport <- function(input, output, session, plotObj, - type, + modelType, predictions = function(){NULL}, plotFun = NULL, - Model = NULL){ + Model = NULL, + mapType = "Map"){ observeEvent(input$export, { showModal(modalDialog( title = "Export Graphic", @@ -30,7 +31,7 @@ plotExport <- function(input, numericInput(session$ns("height"), "Height (px)", value = 800) ), conditionalPanel( - condition = paste0("'", type, "' == 'spatio-temporal-average'"), + condition = paste0("'", modelType, "' == 'spatio-temporal-average'"), ns = session$ns, checkboxInput(session$ns("isTimeSeries"), "Export time series"), conditionalPanel( @@ -52,7 +53,7 @@ plotExport <- function(input, output$exportExecute <- downloadHandler( filename = function(){ - nameFile(plotType = type, exportType = input$exportType, isTimeSeries = input$isTimeSeries) + nameFile(plotType = modelType, exportType = input$exportType, isTimeSeries = input$isTimeSeries) }, content = function(file){ if (!input$isTimeSeries) { @@ -83,7 +84,7 @@ plotExport <- function(input, figFileNames <- sapply(times, function(i) { - nameFile(plotType = type, exportType = input$exportType, + nameFile(plotType = modelType, exportType = input$exportType, isTimeSeries = input$isTimeSeries, i = i) }) diff --git a/R/03-modelResults3D.R b/R/03-modelResults3D.R index 17bd90ca..657be2dc 100644 --- a/R/03-modelResults3D.R +++ b/R/03-modelResults3D.R @@ -1259,7 +1259,8 @@ modelResults3D <- function(input, output, session, isoData, savedMaps, fruitsDat callModule(plotExport, "export", reactive(values$plot), "spatio-temporal-average", predictions = reactive(values$predictions), plotFun = plotFun, - Model = Model + Model = Model, + mapType = reactive(input$mapType) ) callModule(batchPointEstimates, "batch", plotFun, time = TRUE, fruitsData = fruitsData, Model = Model) diff --git a/R/03-modelResults3DKernel.R b/R/03-modelResults3DKernel.R index f9ac4390..971c43db 100644 --- a/R/03-modelResults3DKernel.R +++ b/R/03-modelResults3DKernel.R @@ -1266,7 +1266,8 @@ modelResults3DKernel <- function(input, output, session, isoData, savedMaps, fru callModule(plotExport, "export", reactive(values$plot), "spatio-temporal-average", predictions = reactive(values$predictions), plotFun = plotFun, - Model = Model + Model = Model, + mapType = reactive(input$mapType) ) callModule(batchPointEstimates, "batch", plotFun, time = TRUE, fruitsData = fruitsData, Model = Model) modelParams <- reactive({ diff --git a/man/getHrefTag.Rd b/man/getHrefTag.Rd new file mode 100644 index 00000000..75f9734c --- /dev/null +++ b/man/getHrefTag.Rd @@ -0,0 +1,14 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/03-modelLinkUI.R +\name{getHrefTag} +\alias{getHrefTag} +\title{Get Href} +\usage{ +getHrefTag(url) +} +\arguments{ +\item{url}{url} +} +\description{ +Get Href +} From eb884d7493469c8baa54a9fa0067e7f477dc9932 Mon Sep 17 00:00:00 2001 From: Antonia Runge Date: Mon, 19 Dec 2022 21:22:11 +0100 Subject: [PATCH 2/6] no time series if plot type not map --- R/02-plotExport.R | 84 +++++++++++++++++++++++++---------------------- 1 file changed, 45 insertions(+), 39 deletions(-) diff --git a/R/02-plotExport.R b/R/02-plotExport.R index 797a3e7f..9407a497 100644 --- a/R/02-plotExport.R +++ b/R/02-plotExport.R @@ -11,7 +11,7 @@ plotExport <- function(input, predictions = function(){NULL}, plotFun = NULL, Model = NULL, - mapType = "Map"){ + mapType = reactive("Map")){ observeEvent(input$export, { showModal(modalDialog( title = "Export Graphic", @@ -51,12 +51,19 @@ plotExport <- function(input, replayPlot(plotObj()) }) + isTimeSeriesInput <- reactiveVal(FALSE) + + observe({ + req(!is.null(input$isTimeSeries)) + if (mapType() == "Map") isTimeSeriesInput(input$isTimeSeries) else isTimeSeriesInput(FALSE) + }) + output$exportExecute <- downloadHandler( filename = function(){ - nameFile(plotType = modelType, exportType = input$exportType, isTimeSeries = input$isTimeSeries) + nameFile(plotType = modelType, exportType = input$exportType, isTimeSeries = isTimeSeriesInput()) }, content = function(file){ - if (!input$isTimeSeries) { + if (!isTimeSeriesInput()) { if (input$exportType == "geo-tiff"){ writeGeoTiff(predictions(), file) return() @@ -72,44 +79,43 @@ plotExport <- function(input, replayPlot(plotObj()) dev.off() - return() - } - - minTime <- input$minTime - maxTime <- input$maxTime - intTime <- abs(input$intTime) - - withProgress(message = "Generating series ...", value = 0, { - times <- seq(minTime, maxTime, by = intTime) - - figFileNames <- sapply(times, - function(i) { - nameFile(plotType = modelType, exportType = input$exportType, - isTimeSeries = input$isTimeSeries, i = i) - }) - - for (i in times) { - incProgress(1 / length(times), detail = paste("time: ", i)) - figFilename <- figFileNames[[which(times == i)]] - - if (input$exportType == "geo-tiff"){ - writeGeoTiff(predictions(), figFilename) - } else { - switch( - input$exportType, - png = png(figFilename, width = input$width, height = input$height), - pdf = pdf(figFilename, width = input$width / 72, height = input$height / 72), - tiff = tiff(figFilename, width = input$width, height = input$height), - svg = svg(figFilename, width = input$width / 72, height = input$height / 72) - ) - plotFun()(model = Model(), time = i) - dev.off() + } else { + minTime <- input$minTime + maxTime <- input$maxTime + intTime <- abs(input$intTime) + + withProgress(message = "Generating series ...", value = 0, { + times <- seq(minTime, maxTime, by = intTime) + + figFileNames <- sapply(times, + function(i) { + nameFile(plotType = modelType, exportType = input$exportType, + isTimeSeries = isTimeSeriesInput(), i = i) + }) + + for (i in times) { + incProgress(1 / length(times), detail = paste("time: ", i)) + figFilename <- figFileNames[[which(times == i)]] + + if (input$exportType == "geo-tiff"){ + writeGeoTiff(predictions(), figFilename) + } else { + switch( + input$exportType, + png = png(figFilename, width = input$width, height = input$height), + pdf = pdf(figFilename, width = input$width / 72, height = input$height / 72), + tiff = tiff(figFilename, width = input$width, height = input$height), + svg = svg(figFilename, width = input$width / 72, height = input$height / 72) + ) + plotFun()(model = Model(), time = i) + dev.off() + } } - } - zipr(file, figFileNames) - unlink(figFileNames) - }) + zipr(file, figFileNames) + unlink(figFileNames) + }) + } } ) } From d45cd4129581d1a5e27409d4aa1b7c9d688c7f25 Mon Sep 17 00:00:00 2001 From: Antonia Runge Date: Tue, 20 Dec 2022 09:50:55 +0100 Subject: [PATCH 3/6] fix checks for is.null --- R/02-leafletPointSettings.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/02-leafletPointSettings.R b/R/02-leafletPointSettings.R index d987e550..55e42092 100644 --- a/R/02-leafletPointSettings.R +++ b/R/02-leafletPointSettings.R @@ -82,10 +82,10 @@ updateDataOnLeafletMap <- function(map, isoData, leafletPointValues) { map <- map %>% cleanDataFromMap() - if (is.null(isoData) || is.null(isoData$latitude) || all(is.na(isoData$latitude)) || - is.null(isoData$longitude) || all(is.na(isoData$longitude))) return(map) + if (is.null(isoData) || is.null(isoData[["latitude"]]) || all(is.na(isoData[["latitude"]])) || + is.null(isoData[["longitude"]]) || all(is.na(isoData[["longitude"]]))) return(map) - isoData <- isoData[(!is.na(isoData$longitude) & !is.na(isoData$latitude)), ] + isoData <- isoData[(!is.na(isoData[["longitude"]]) & !is.na(isoData[["latitude"]])), ] if (leafletPointValues$clusterPoints) { return(drawClustersOnMap(map, isoData)) From 25c442754da0f5fcf3aabe71e80959d01692d971 Mon Sep 17 00:00:00 2001 From: Antonia Runge Date: Tue, 20 Dec 2022 09:51:40 +0100 Subject: [PATCH 4/6] fix naming conflicts --- R/03-dataExplorer.R | 50 ++++++++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 16 deletions(-) diff --git a/R/03-dataExplorer.R b/R/03-dataExplorer.R index 2ddb8b9c..ebf1c09d 100644 --- a/R/03-dataExplorer.R +++ b/R/03-dataExplorer.R @@ -245,7 +245,11 @@ dataExplorerServer <- function(id) { ) # Extract isoDataFull (both skins) ---- - observe({ + observeEvent(list(locationFields$longitude(), + locationFields$latitude(), + locationFields$coordType(), + calibrateMethod(), + calLevel()), { req(isoDataRaw()) d <- isoDataRaw() @@ -286,26 +290,40 @@ dataExplorerServer <- function(id) { }, silent = TRUE) if (class(dCoord) == "try-error") { - alert( - paste0( - "Conversion of coordinates has failed. Please select appropriate ", - "longitude / latitude fields and coordinate format." - ) - ) - if (locationFields$longitude() == "longitude") { - # reset to origial - d$longitude <- isoDataRaw()[[locationFields$longitude()]] + ### Conversion failure ---- + if (locationFields$longitude() == "longitude" || + locationFields$latitude() == "latitude") { + if (locationFields$longitude() == "longitude") { + # rename original to avoid name conflicts + tmpIsoDataRaw <- isoDataRaw() + tmpIsoDataRaw[[paste0(locationFields$longitude(), "_orig")]] <- + tmpIsoDataRaw[["longitude"]] + tmpIsoDataRaw[["longitude"]] <- NULL + isoDataRaw(tmpIsoDataRaw) + } + + if (locationFields$latitude() == "latitude") { + # rename original to avoid name conflicts + tmpIsoDataRaw <- isoDataRaw() + tmpIsoDataRaw[[paste0(locationFields$latitude(), "_orig")]] <- + tmpIsoDataRaw[["latitude"]] + tmpIsoDataRaw[["latitude"]] <- NULL + isoDataRaw(tmpIsoDataRaw) + } } else { - d$longitude <- NULL - } + alert( + paste0( + "Conversion of coordinates has failed. Please select appropriate ", + "longitude / latitude fields and coordinate format. ", + "Columns longitude and latitude were removed (renamed)." + ) + ) - if (locationFields$latitude() == "latitude") { - # reset to origial - d$latitude <- isoDataRaw()[[locationFields$latitude()]] - } else { + d$longitude <- NULL d$latitude <- NULL } } else { + ### Conversion success ---- showNotification( paste0( "Conversion of coordinates succeeded. ", From 0d3151ff65e6605447ddf0375a295a39a0d5398c Mon Sep 17 00:00:00 2001 From: Antonia Runge Date: Tue, 20 Dec 2022 10:01:34 +0100 Subject: [PATCH 5/6] hide option for time series in UI --- R/02-plotExport.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/R/02-plotExport.R b/R/02-plotExport.R index 9407a497..a0ce7ae4 100644 --- a/R/02-plotExport.R +++ b/R/02-plotExport.R @@ -31,7 +31,8 @@ plotExport <- function(input, numericInput(session$ns("height"), "Height (px)", value = 800) ), conditionalPanel( - condition = paste0("'", modelType, "' == 'spatio-temporal-average'"), + condition = paste0("'", modelType, "' == 'spatio-temporal-average' & ", + "'", mapType(), "' == 'Map'"), ns = session$ns, checkboxInput(session$ns("isTimeSeries"), "Export time series"), conditionalPanel( From 97458178f0c4ce1dc16b10a5c671b20415c48d21 Mon Sep 17 00:00:00 2001 From: Antonia Runge Date: Tue, 20 Dec 2022 10:06:34 +0100 Subject: [PATCH 6/6] update description and news.md --- DESCRIPTION | 2 +- NEWS.md | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index a74c44a3..3c8383b8 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: MpiIsoApp Title: Pandora & IsoMemo spatiotemporal modeling -Version: 22.12.2 +Version: 22.12.3 Author: INWT Statistics GmbH Maintainer: INWT Description: Shiny App contains: a data explorer tab, an interactive map and a static map, which should present model results. diff --git a/NEWS.md b/NEWS.md index de40bd39..e6931652 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,15 @@ # MpiIsoApp development version +## MpiIsoApp 22.12.3 + +### Updates +- _export of plots_ after modelling: hide option to create a time series for +_Time Course_ plot type (#8) + +### Bug Fixes +- fix naming issue when data contains columns exactly named "latitude" or "longitude" + - columns will be renamed if coordinate conversion fails + ## MpiIsoApp 22.12.2 ### Updates