Skip to content

Commit

Permalink
Feature/questionnaire feedback (#32)
Browse files Browse the repository at this point in the history
* rename files and inputs

* update news

* remove typo

* overlay title over image and plot, add table caption

* update man

* update namespace

* remove tag

* install libmagick

---------

Co-authored-by: Antonia Runge <[email protected]>
  • Loading branch information
f-lukas and arunge authored Oct 14, 2024
1 parent 602b18b commit d04470d
Show file tree
Hide file tree
Showing 22 changed files with 161 additions and 60 deletions.
4 changes: 3 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: MapR
Title: Display temporal and temperature graphical files for Isomemo
Version: 24.6.0
Version: 24.10.0
Authors@R: c(person("Lukas", "Fuchs", email = "[email protected]", role = c("aut", "cre")))
Description: An App to display temporal and temperature graphical files for Isomemo.
License: GPL (>= 3)
Expand All @@ -12,6 +12,8 @@ Imports:
DataTools (>= 24.06.0),
DT,
futile.logger,
graphics,
magick,
magrittr,
pastclim,
rjson,
Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ RUN apt-get update \
&& apt-get install -y --no-install-recommends \
qpdf \
pandoc \
libmagick++-dev \
&& echo "options(repos = c(getOption('repos'), PANDORA = 'https://Pandora-IsoMemo.github.io/drat/'))" >> /usr/local/lib/R/etc/Rprofile.site \
&& installPackage

Expand Down
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ importFrom(DataTools,extractObjectFromFile)
importFrom(DataTools,importDataServer)
importFrom(DataTools,importDataUI)
importFrom(DataTools,importOptions)
importFrom(graphics,title)
importFrom(magick,image_annotate)
importFrom(magick,image_read)
importFrom(magick,image_write)
importFrom(magrittr,"%>%")
importFrom(rjson,fromJSON)
importFrom(shinyTools,dataExportButton)
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# MapR 24.10.0

## Updates
- mapr file extension is used instead of zipm
- labels for inputs have been updated

# MapR 24.6.0

## New Features
Expand Down
2 changes: 2 additions & 0 deletions R/00-Namespace.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#' @importFrom rjson fromJSON
#' @importFrom DataTools downloadModelServer downloadModelUI extractNotes extractObjectFromFile
#' importDataUI importDataServer importOptions
#' @importFrom graphics title
#' @importFrom magick image_annotate image_read image_write
#' @importFrom shinyTools dataExportButton dataExportServer headerButtonsUI includeShinyToolsCSS
#' @importFrom yaml read_yaml

Expand Down
56 changes: 23 additions & 33 deletions R/01-mapPanelModule.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mapPanelUI <- function(id) {
sidebarLayout(
sidebarPanel(
width = 2,
importDataUI(ns("file_import"), label = "Import ZIP file"),
importDataUI(ns("file_import"), label = "Load MapR file"),
createVariableSelectionInputs(id),
br(),
fluidRow(
Expand All @@ -36,13 +36,7 @@ mapPanelUI <- function(id) {
width = 10,
fluidRow(
column(12,
align = "center",
uiOutput(outputId = ns("plot_title"))
)
),
fluidRow(
column(12,
align = "center",
align = "left",
plotUI(id = ns("mainplot")),
tableUI(id = ns("maintable"))
)
Expand Down Expand Up @@ -100,44 +94,40 @@ mapPanelServer <- function(id) {
# setup download of a session
downloadSessionServer(input, output, session, uploaded_zip, upload_description)

title_format <- reactiveValues()

observe({
title_format[["text"]] <- input[["title-text"]]
title_format[["color"]] <- input[["title-color"]]
title_format[["size"]] <- input[["title-fontsize"]]
})

# Show plot and plot formatting options when button is clicked
observeShowPlot(
input = input,
output = output,
session = session,
image_list = image_list,
questionnaire = questionnaire
questionnaire = questionnaire,
title_format = title_format
)

observeShowTable(input = input,
output = output,
session = session,
image_list = image_list,
table_data = table_data)
observeShowTable(
input = input,
output = output,
session = session,
image_list = image_list,
table_data = table_data,
title_format = title_format
)

dataExportServer(
id = "download",
dataFun = reactive({ function() table_data() }),
dataFun = reactive({
function() table_data()
}),
filename = "data"
)

# Plot Title
output$plot_title <- renderUI({
text <- input[["title-text"]]
col <- input[["title-color"]]
fontsize <- paste0(input[["title-fontsize"]], "px")
style <- paste("font-size: ", fontsize, ";", "color: ", col, ";", sep = "")
HTML(paste("<span style='", style, "'>", text, "</span>"))
}) %>%
bindEvent(
c(
input[["display_plot-button"]],
input[["title-text"]],
input[["title-fontsize"]],
input[["title-color"]]
),
ignoreInit = TRUE
)
}
)
}
4 changes: 2 additions & 2 deletions R/02-createVariableSelectionInputs.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ createVariableSelectionInputs <- function(id) {
id = ns("variable_selection_inputs"),
selectizeInputUI(
id = ns("group_name"),
label = "Group Name",
label = "Main selection",
choices = NULL
),
selectizeInputUI(
Expand All @@ -19,7 +19,7 @@ createVariableSelectionInputs <- function(id) {
),
selectizeInputUI(
id = ns("measure"),
label = "Measure",
label = "Parameter",
choices = NULL
),
br(),
Expand Down
7 changes: 4 additions & 3 deletions R/02-observeShowPlot.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
#' @param session session from server function
#' @param image_list reactive image list
#' @param questionnaire reactive questionnaire
observeShowPlot <- function(input, output, session, image_list, questionnaire) {
#' @param title_format reactive list with title text and format arguments
observeShowPlot <- function(input, output, session, image_list, questionnaire, title_format) {
observe({
shinyjs::show(id = "title-options", anim = TRUE)
shinyjs::show(id = "plot_title", anim = TRUE)
shinyjs::hide(id = "maintable-table")
shinyjs::show(id = "mainplot-plot")

Expand All @@ -24,7 +24,8 @@ observeShowPlot <- function(input, output, session, image_list, questionnaire) {
path = paste0(tempdir(), "/data/", imageInfos$address),
file_type = imageInfos$file_type,
variable = imageInfos$variable,
time = imageInfos$time
time = imageInfos$time,
title_format = title_format
)

updateTextInput(
Expand Down
49 changes: 40 additions & 9 deletions R/03-plotModule.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,61 @@ plotUI <- function(id) {
#' @param file_type file type of file
#' @param variable variable from user selection
#' @param time time from user selection
plotServer <- function(id, path, file_type, variable = NULL, time = NULL) {
#' @param title_format reactive list with title text and format arguments
plotServer <- function(id, path, file_type, title_format, variable = NULL, time = NULL) {
moduleServer(
id,
function(input, output, session) {
if (!file_type %in% c("png", "nc")) {
shinyjs::alert("file_type specified in json must be png or nc")
} else if (file_type == "png") {
output$plot <- renderImage(
{
list(src = path, contentType = "image/png", alt = "Plot")
},
deleteFile = FALSE
)
output$plot <- renderImage({
temp_file <- addTitleToPNG(path, title_format = title_format)
list(src = temp_file,
contentType = "image/png",
alt = "Plot")
}, deleteFile = TRUE)
} else if (file_type == "nc") {
plot_data <- pastclim::region_slice(
time_bp = time,
bio_variables = variable,
dataset = "custom",
path_to_nc = path
)
output$plot <- renderPlot(
output$plot <- renderPlot({
terra::plot(plot_data)
)
title(main = title_format[["text"]],
col.main = title_format[["color"]],
cex.main = title_format[["size"]] / 10)
})
}
}
)
}

#' Add title to PNG image
#'
#' @param path path to the image
#' @param title_format list with title text and format arguments
#'
addTitleToPNG <- function(path,
title_format) {
# Read the original image
img <- image_read(path)

# Create an image with the title overlaid
img_with_title <- image_annotate(
img,
text = title_format[["text"]],
size = title_format[["size"]], # Font size for the title
color = title_format[["color"]], # Text color
gravity = "north", # Position the text at the top center
location = "+0+20" # Adjust vertical offset
)

# Save the new image to a temporary file
temp_file <- tempfile(fileext = ".png")
image_write(img_with_title, path = temp_file, format = "png")

temp_file
}
28 changes: 22 additions & 6 deletions R/03-tableModule.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ tableUI <- function(id) {
#'
#' @param id id of module
#' @param df data frame to be displayed in table
tableServer <- function(id, df) {
#' @param title_format reactive list with title text and format arguments
tableServer <- function(id, df, title_format) {
moduleServer(
id,
function(input, output, session) {
output$table <- DT::renderDataTable({
DT::datatable(df,
rownames = FALSE,
caption = formatCaption(title_format),
# escape = FALSE,
# filter = "top",
style = "bootstrap",
Expand All @@ -38,10 +40,10 @@ tableServer <- function(id, df) {
#' @param session session from server function
#' @param image_list reactive image list
#' @param table_data reactive table data
observeShowTable <- function(input, output, session, image_list, table_data) {
#' @param title_format reactive list with title text and format arguments
observeShowTable <- function(input, output, session, image_list, table_data, title_format) {
observe({
shinyjs::hide(id = "title-options")
shinyjs::hide(id = "plot_title")
shinyjs::show(id = "title-options")
shinyjs::hide(id = "mainplot-plot")
shinyjs::show(id = "maintable-table")
shinyjs::show(
Expand All @@ -54,7 +56,7 @@ observeShowTable <- function(input, output, session, image_list, table_data) {
locations <- data.frame(latitude = input[["latitude"]], longitude = input[["longitude"]])
path <- paste0(tempdir(), "/data/", imageInfos$address)
if (imageInfos$file_type[[1]] != "nc") {
shinyjs::alert("file_type specified in json must be nc for time plot.")
shinyjs::alert("file_type specified in json must be nc for 'Time data'.")
} else {
df <- pastclim::location_series(
x = locations,
Expand All @@ -69,11 +71,25 @@ observeShowTable <- function(input, output, session, image_list, table_data) {
table_data(df)
tableServer(
id = "maintable",
df = df
df = df,
title_format = title_format
)
}
}) %>%
bindEvent(input[["display_table-button"]],
ignoreInit = TRUE
)
}

#' Create a caption for a table from a title object
#'
#' @param title_format named list with title text and format arguments
#'
#' @return (HTML) caption for a table
formatCaption <- function(title_format) {
text <- title_format[["text"]]
col <- title_format[["color"]]
fontsize <- paste0(title_format[["size"]], "px")
style <- paste("font-size: ", fontsize, ";", "color: ", col, ";", sep = "")
HTML(paste("<span style='", style, "'>", text, "</span>"))
}
Binary file not shown.
Binary file not shown.
Binary file added inst/app/exampleZip/mapR_test_session.mapr
Binary file not shown.
Binary file removed inst/app/exampleZip/mapR_test_session.zipm
Binary file not shown.
4 changes: 2 additions & 2 deletions inst/config.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
defaultSource: "file" # for import of data
# file types that are allowed for import from Pandora ("ckan")
ckanFileTypes:
- "zipm"
- "mapr"
- "zip"
defaultFileName: "mapR_session" # for download of user inputs
fileExtension: "zipm" # for import of models
fileExtension: "mapr" # for import of models
rPackageName: "MapR"
16 changes: 16 additions & 0 deletions man/addTitleToPNG.Rd

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

17 changes: 17 additions & 0 deletions man/formatCaption.Rd

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

11 changes: 10 additions & 1 deletion man/observeShowPlot.Rd

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

Loading

0 comments on commit d04470d

Please sign in to comment.