-
Notifications
You must be signed in to change notification settings - Fork 1
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
DSSM 24.08.0: Feature/203 json for mapr #234
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,20 +63,42 @@ plotExport <- function(input, | |
choices = c( | ||
"Gif + graphic files" = "gifAndZip", | ||
"Graphic files" = "onlyZip", | ||
"Gif file" = "onlyGif"))), | ||
"Gif file" = "onlyGif", | ||
"MapR files" = "mapr")), | ||
conditionalPanel( | ||
condition = "input.typeOfSeries == 'mapr'", | ||
ns = session$ns, | ||
helpText("MapR only supports .png export. Ignoring 'Filetype' input.") | ||
) | ||
), | ||
column(width = 4, | ||
conditionalPanel( | ||
condition = "input.typeOfSeries != 'onlyZip'", | ||
condition = "input.typeOfSeries == 'gifAndZip' || input.typeOfSeries == 'onlyGif'", | ||
ns = session$ns, | ||
numericInput(session$ns("fpsGif"), "Frames per second", value = 2, min = 1, max = 10) | ||
)), | ||
column(width = 4, | ||
style = "margin-top: 1.5em;", | ||
), | ||
conditionalPanel( | ||
condition = "input.typeOfSeries != 'onlyZip'", | ||
condition = "input.typeOfSeries == 'mapr'", | ||
ns = session$ns, | ||
textInput(session$ns("mapr-group"), "Group", value = "Groupname"), | ||
textInput(session$ns("mapr-measure"), "Measure", value = "Mean") | ||
) | ||
), | ||
conditionalPanel( | ||
condition = "input.typeOfSeries == 'gifAndZip' || input.typeOfSeries == 'onlyGif'", | ||
ns = session$ns, | ||
column(width = 4, style = "margin-top: 2em;", | ||
checkboxInput(session$ns("reverseGif"), "Reverse time order") | ||
)) | ||
) | ||
), | ||
conditionalPanel( | ||
condition = "input.typeOfSeries == 'mapr'", | ||
ns = session$ns, | ||
column(width = 4, | ||
textInput(session$ns("mapr-variable"), "Variable", value = "Variable"), | ||
textInput(session$ns("mapr-measureunit"), "Measure unit", value = "Measure Unit") | ||
) | ||
) | ||
) | ||
) | ||
), | ||
|
@@ -85,6 +107,15 @@ plotExport <- function(input, | |
)) | ||
}) | ||
|
||
observe({ | ||
if(any(c(input$`mapr-group`,input$`mapr-variable`,input$`mapr-measure`,input$`mapr-measureunit`) == "") && input$typeOfSeries == "mapr"){ | ||
shinyjs::disable("exportExecute") | ||
} else { | ||
shinyjs::enable("exportExecute") | ||
} | ||
}) %>% bindEvent(c(input$typeOfSeries,input$`mapr-group`,input$`mapr-variable`,input$`mapr-measure`,input$`mapr-measureunit`), | ||
ignoreInit = TRUE) | ||
|
||
output$plot <- renderPlot({ | ||
replayPlot(plotObj()) | ||
}) | ||
|
@@ -116,8 +147,16 @@ plotExport <- function(input, | |
plotObj = plotObj(), | ||
predictions = predictions()) %>% | ||
suppressWarnings() %>% | ||
tryCatchWithWarningsAndErrors(errorTitle = "Export of graphic faild") | ||
tryCatchWithWarningsAndErrors(errorTitle = "Export of graphic failed") | ||
} else { | ||
if (input$typeOfSeries == "mapr") { | ||
exportMapRFiles(file = file, | ||
plotFun = plotFun(), | ||
Model = Model(), | ||
input = input) %>% | ||
suppressWarnings() %>% | ||
tryCatchWithWarningsAndErrors(errorTitle = "Export of series of graphics failed") | ||
} else { | ||
exportGraphicSeries(exportType = exportType(), | ||
file = file, | ||
width = input$width, | ||
|
@@ -133,7 +172,8 @@ plotExport <- function(input, | |
reverseGif = input$reverseGif, | ||
fpsGif = input$fpsGif) %>% | ||
suppressWarnings() %>% | ||
tryCatchWithWarningsAndErrors(errorTitle = "Export of series of graphics faild") | ||
tryCatchWithWarningsAndErrors(errorTitle = "Export of series of graphics failed") | ||
} | ||
} | ||
} | ||
) | ||
|
@@ -148,9 +188,30 @@ plotExport <- function(input, | |
#' @param typeOfSeries one of "gifAndZip", "onlyZip", "onlyGif" | ||
#' @param i (numeric) number of i-th plot of a series of plots | ||
nameFile <- function(plotType, exportType, isTimeSeries, typeOfSeries, i = NULL) { | ||
paste0(getFileName(plotType = plotType, isTimeSeries = isTimeSeries, i = i), | ||
getFileExt(exportType = exportType, isTimeSeries = isTimeSeries, | ||
typeOfSeries = typeOfSeries, isCollection = is.null(i))) | ||
# set file name | ||
fileName <- getFileName(plotType = plotType, isTimeSeries = isTimeSeries, i = i) | ||
|
||
# set file extension | ||
if (!isTimeSeries || !is.null(i)) { | ||
## file extension for single plots: from user input 'exportType' | ||
|
||
# use 'tif' instead of 'geo-tiff' | ||
if (exportType == 'geo-tiff') { | ||
fileExt <- "tif" | ||
} else { | ||
fileExt <- exportType | ||
} | ||
} else { | ||
## file extension for series of plots: from user input 'typeOfSeries' | ||
fileExt <- switch(typeOfSeries, | ||
gifAndZip = "zip", | ||
onlyZip = "zip", | ||
onlyGif = "gif", | ||
mapr = "zipm") | ||
} | ||
|
||
# return file name with extension | ||
paste0(fileName, ".", fileExt) | ||
} | ||
|
||
|
||
|
@@ -163,21 +224,92 @@ getFileName <- function(plotType, isTimeSeries, i = NULL) { | |
plotType | ||
} | ||
|
||
exportMapRFiles <- function(file, plotFun, Model, input) { | ||
withProgress(message = "Generating series ...", value = 0, { | ||
times <- seq(input$minTime, input$maxTime, by = abs(input$intTime)) | ||
|
||
#' Get File Ext | ||
#' | ||
#' Get file extension | ||
#' | ||
#' @param isCollection (logical) TRUE if this is the container file, FALSE if this is an element file | ||
#' @inheritParams nameFile | ||
getFileExt <- function(exportType, isTimeSeries, typeOfSeries, isCollection = FALSE) { | ||
if (exportType == 'geo-tiff') exportType <- "tif" | ||
# create all file names to be put into a zip | ||
figFileNames <- sapply(times, | ||
function(i) { | ||
paste0("data","/", | ||
gsub(" ", "", input$`mapr-group`),"/", | ||
gsub(" ", "", input$`mapr-variable`),"/", | ||
gsub(" ", "", input$`mapr-measure`),"/", | ||
i,".png") | ||
}) | ||
|
||
if (!isTimeSeries || !isCollection) return(paste0(".", exportType)) | ||
lapply(unique(dirname(figFileNames)), dir.create, recursive = TRUE, showWarnings = FALSE) | ||
|
||
if (typeOfSeries == "onlyGif") return(".gif") else return(".zip") | ||
for (i in times) { | ||
incProgress(1 / length(times), detail = paste("time: ", i)) | ||
figFilename <- figFileNames[[which(times == i)]] | ||
|
||
# save desired file type | ||
writeGraphics(exportType = "png", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
see above |
||
plot = plotFun(model = Model, time = i), | ||
filename = figFilename, | ||
width = input$width, | ||
height = input$height) | ||
} | ||
|
||
json_list <- create_image_list_json(input, figFileNames, times) | ||
|
||
# Save JSON content to a temporary file | ||
json_file <- file.path("image_list.json") | ||
jsonlite::write_json(json_list, json_file, pretty = TRUE) | ||
|
||
zip(file, files = c(json_file, figFileNames)) | ||
|
||
# Clean up the temporary files | ||
file.remove(figFileNames) | ||
file.remove(json_file) | ||
unlink(file.path("data"), recursive = TRUE) | ||
}) | ||
} | ||
|
||
create_image_list_json <- function(input, figFileNames, times){ | ||
image_list <- list( | ||
Selections = list( | ||
list( | ||
Group = input$`mapr-group`, | ||
Group_DOI = 1, | ||
Variable = list( | ||
list( | ||
Variable_name = input$`mapr-variable`, | ||
Variable_DOI = 1, | ||
Measure = list( | ||
list( | ||
Measure_name = input$`mapr-measure`, | ||
Measure_unit = input$`mapr-measureunit`, | ||
images = list( | ||
) | ||
) | ||
) | ||
) | ||
) | ||
) | ||
) | ||
) | ||
|
||
for (image in figFileNames){ | ||
|
||
time <- as.character(times[[which(figFileNames == image)]]) | ||
|
||
single_image <- list( | ||
x_display_value = time, | ||
file_type = "png", | ||
location_type = "local", | ||
address = gsub("data/","",image) | ||
) | ||
|
||
# Add the images to the list | ||
image_list$Selections[[1]]$Variable[[1]]$Measure[[1]]$images <- append(image_list$Selections[[1]]$Variable[[1]]$Measure[[1]]$images, list(single_image)) | ||
} | ||
|
||
image_list | ||
} | ||
|
||
|
||
exportGraphicSeries <- function(exportType, file, | ||
width, height, plotFun, Model, predictions, | ||
modelType, minTime, maxTime, intTime, | ||
|
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is MapR only able to read
".png"
or could the type be set by the user viainput$exportType
as for the other series of plots?In both cases, please consider to check (and if necessary to update) the choices for
"exportType"
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
png
is indeed the only supported file type from the file types that can by selected by the user. The other supported file type in MapR isnc
. Therefore, and also because the export zipm file is intended to be uploaded to mapR only and not to be used without the app or something, I thought it might be useful to ignore the file type that was selected. Are you fine with it or should I still add anything? Of course I could change file type to png if mapr is selected. However, I wanted to keep the complexity low. Another option would be to display a note or something. What do you think?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I think than it is good to make a note for the user, e.g. "MapR only supports .png export. Ignoring 'Filetype' input."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added the helptext