Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 22.12.3: Feat/8 hide series in time plot #85

Merged
merged 6 commits into from
Dec 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
Description: Shiny App contains: a data explorer tab, an interactive map and a static map, which should present model results.
Expand Down
10 changes: 10 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 3 additions & 3 deletions R/02-leafletPointSettings.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
90 changes: 49 additions & 41 deletions R/02-plotExport.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ plotExport <- function(input,
output,
session,
plotObj,
type,
modelType,
predictions = function(){NULL},
plotFun = NULL,
Model = NULL){
Model = NULL,
mapType = reactive("Map")){
observeEvent(input$export, {
showModal(modalDialog(
title = "Export Graphic",
Expand All @@ -30,7 +31,8 @@ plotExport <- function(input,
numericInput(session$ns("height"), "Height (px)", value = 800)
),
conditionalPanel(
condition = paste0("'", type, "' == 'spatio-temporal-average'"),
condition = paste0("'", modelType, "' == 'spatio-temporal-average' & ",
"'", mapType(), "' == 'Map'"),
ns = session$ns,
checkboxInput(session$ns("isTimeSeries"), "Export time series"),
conditionalPanel(
Expand All @@ -50,12 +52,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 = type, 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()
Expand All @@ -71,44 +80,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 = type, 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)
})
}
}
)
}
Expand Down
50 changes: 34 additions & 16 deletions R/03-dataExplorer.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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. ",
Expand Down
3 changes: 2 additions & 1 deletion R/03-modelResults3D.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
3 changes: 2 additions & 1 deletion R/03-modelResults3DKernel.R
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
14 changes: 14 additions & 0 deletions man/getHrefTag.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.