diff --git a/DESCRIPTION b/DESCRIPTION index 1ed5ce4..0fddb2a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: MapR Title: Display temporal and temperature graphical files for Isomemo -Version: 24.2.0 +Version: 24.3.0 Authors@R: c(person("Lukas", "Fuchs", email = "lukas.fuchs@inwt-statistics.de", role = c("aut", "cre"))) Description: An App to display temporal and temperature graphical files for Isomemo. License: GPL (>= 3) @@ -10,12 +10,13 @@ RoxygenNote: 7.2.3 Imports: colourpicker, DataTools (>= 23.12.2), + DT, magrittr, pastclim, rjson, shiny, shinyjs, - shinyTools, + shinyTools (>= 24.03.1), shinyWidgets, terra, yaml diff --git a/NAMESPACE b/NAMESPACE index e3f0ce7..20e0d7b 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -9,5 +9,9 @@ importFrom(DataTools,importDataServer) importFrom(DataTools,importDataUI) importFrom(magrittr,"%>%") importFrom(rjson,fromJSON) +importFrom(shinyTools,dataExportButton) +importFrom(shinyTools,dataExportServer) +importFrom(shinyTools,headerButtonsUI) +importFrom(shinyTools,includeShinyToolsCSS) importFrom(stats,setNames) importFrom(yaml,read_yaml) diff --git a/NEWS.md b/NEWS.md index 22ea95f..ab7e837 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,13 @@ +# MapR 24.3.0 + +## Updates +- applying exportData module from shinyTools package, removing the code from this package + +# MapR 24.2.1 + +## New Features +- display and download of time plot data + # MapR 24.2.0 ## New Features diff --git a/R/00-Namespace.R b/R/00-Namespace.R index 192cca4..d9f8148 100644 --- a/R/00-Namespace.R +++ b/R/00-Namespace.R @@ -15,7 +15,7 @@ #' @rawNamespace import(shiny) #' @importFrom rjson fromJSON #' @importFrom DataTools importDataUI importDataServer -#' @importFrom shinyTools headerButtonsUI includeShinyToolsCSS +#' @importFrom shinyTools dataExportButton dataExportServer headerButtonsUI includeShinyToolsCSS #' @importFrom yaml read_yaml NULL diff --git a/R/01-mapPanelModule.R b/R/01-mapPanelModule.R index 4bf1276..6cc0de8 100644 --- a/R/01-mapPanelModule.R +++ b/R/01-mapPanelModule.R @@ -20,6 +20,12 @@ mapPanelUI <- function(id) { id = ns("display_plot"), label = "Display plot" ) + ), + shinyjs::hidden( + actionButtonUI( + id = ns("display_table"), + label = "Display time data" + ) ) ) ), @@ -36,7 +42,8 @@ mapPanelUI <- function(id) { fluidRow( column(12, align = "center", - plotUI(id = ns("mainplot")) + plotUI(id = ns("mainplot")), + tableUI(id = ns("maintable")) ) ) ) @@ -54,6 +61,7 @@ mapPanelServer <- function(id) { function(input, output, session) { image_list <- reactiveVal() questionnaire <- reactiveVal() + table_data <- reactiveVal() # Load zip file uploadedZip <- importDataServer("file_import", @@ -92,6 +100,18 @@ mapPanelServer <- function(id) { questionnaire = questionnaire ) + observeShowTable(input = input, + output = output, + session = session, + image_list = image_list, + table_data = table_data) + + dataExportServer( + id = "download", + dataFun = reactive({ function() table_data() }), + filename = "data" + ) + # Plot Title output$plot_title <- renderUI({ text <- input[["title-text"]] diff --git a/R/02-createVariableSelectionInputs.R b/R/02-createVariableSelectionInputs.R index a9ae398..51a7226 100644 --- a/R/02-createVariableSelectionInputs.R +++ b/R/02-createVariableSelectionInputs.R @@ -31,7 +31,7 @@ createVariableSelectionInputs <- function(id) { c(1, 2), c( "Single Map", - "Time plot" + "Time data" ) ) ) @@ -51,6 +51,43 @@ createVariableSelectionInputs <- function(id) { selected = c(2015, 2017) ) ), + fluidRow( + column(6, + align = "center", + shinyjs::hidden( + numericInput( + inputId = ns("latitude"), + label = "Latitude", + value = 50.92, + min = -90, + max = 90 + ) + ) + ), + column(6, + align = "center", + shinyjs::hidden( + numericInput( + inputId = ns("longitude"), + label = "Longitude", + value = 11.58, + min = -180, + max = 180 + ) + ) + ) + ), + br(), + fluidRow( + column(12, + align = "center", + shinyjs::hidden( + dataExportButton( + id = ns("download") + ) + ) + ) + ) )) ) } diff --git a/R/02-observeEnableActionButton.R b/R/02-observeEnableActionButton.R index 7878635..75216b4 100644 --- a/R/02-observeEnableActionButton.R +++ b/R/02-observeEnableActionButton.R @@ -6,14 +6,55 @@ observeEnableActionButton <- function(input, image_list, questionnaire) { observe({ if (!is.null(image_list())) { # in case image_list is available + if (input[["time_switch-buttons"]] == 1) { + shinyjs::hide(id = "display_table-button") + shinyjs::hide(id = "latitude") + shinyjs::hide(id = "longitude") + shinyjs::hide(id = "download-export") + shinyjs::show( + id = "display_plot-button", + anim = TRUE, + animType = "fade", + time = 1 + ) + } else { + shinyjs::hide(id = "display_plot-button") + shinyjs::show( + id = "display_table-button", + anim = TRUE, + animType = "fade", + time = 1 + ) + shinyjs::show( + id = "latitude", + anim = TRUE, + animType = "fade", + time = 1 + ) + shinyjs::show( + id = "longitude", + anim = TRUE, + animType = "fade", + time = 1 + ) + } if (!is.null(input[["group_name-selectize"]]) && !is.null(input[["variable-selectize"]]) && !is.null(input[["measure-selectize"]])) { shinyjs::enable(id = "display_plot-button") + shinyjs::enable(id = "display_table-button") } else { shinyjs::disable(id = "display_plot-button") + shinyjs::disable(id = "display_table-button") } - } else { # in case questionnaire is available + } else if (!is.null(questionnaire())) { # in case questionnaire is available + shinyjs::hide(id = "display_table-button") + shinyjs::show( + id = "display_plot-button", + anim = TRUE, + animType = "fade", + time = 1 + ) inputsFilled <- sapply(1:length(questionnaire()$Questions), function(x) (!is.null(input[[paste0("question_", x)]]) && !is.na(input[[paste0("question_", x)]]))) if (all(inputsFilled)) { shinyjs::enable(id = "display_plot-button") diff --git a/R/02-observeShowAndHideInputs.R b/R/02-observeShowAndHideInputs.R index 46fe1c1..7f962f7 100644 --- a/R/02-observeShowAndHideInputs.R +++ b/R/02-observeShowAndHideInputs.R @@ -34,12 +34,5 @@ observeShowAndHideInputs <- function(input, output, session, uploadedZip, image_ removeUI(selector = "#map_panel-questionnaire_inputs", immediate = TRUE) # remove old questionnaire inputs questionnaire(NULL) # reset questionnaire } - - shinyjs::show( - id = "display_plot-button", - anim = TRUE, - animType = "fade", - time = 1 - ) }) %>% bindEvent(uploadedZip(), ignoreInit = TRUE) } diff --git a/R/02-observeShowPlot.R b/R/02-observeShowPlot.R index 56a2242..1ee30e1 100644 --- a/R/02-observeShowPlot.R +++ b/R/02-observeShowPlot.R @@ -8,7 +8,9 @@ observeShowPlot <- function(input, output, session, image_list, questionnaire) { observe({ shinyjs::show(id = "title-options", anim = TRUE) - output[["mainplot-plot"]] <- NULL + shinyjs::show(id = "plot_title", anim = TRUE) + shinyjs::hide(id = "maintable-table") + shinyjs::show(id = "mainplot-plot") if (!is.null(image_list())) { imageInfos <- prepareImageListImage(input = input, image_list = image_list) diff --git a/R/03-tableModule.R b/R/03-tableModule.R new file mode 100644 index 0000000..d1f235b --- /dev/null +++ b/R/03-tableModule.R @@ -0,0 +1,79 @@ +#' UI function of table module +#' +#' @param id id of module +tableUI <- function(id) { + ns <- NS(id) + DT::dataTableOutput(ns("table"), height = "800px", width = "80%") +} + + +#' Server function of table module +#' +#' @param id id of module +#' @param df data frame to be displayed in table +tableServer <- function(id, df) { + moduleServer( + id, + function(input, output, session) { + output$table <- DT::renderDataTable({ + DT::datatable(df, + rownames = FALSE, + # escape = FALSE, + # filter = "top", + style = "bootstrap", + options = list( + pageLength = 25 + ), + selection = list(mode = "single", target = "cell") + ) + }) + } + ) +} + +#' Observer to show table when display button is clicked +#' +#' @param input input object from server function +#' @param output output object from server function +#' @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) { + observe({ + shinyjs::hide(id = "title-options") + shinyjs::hide(id = "plot_title") + shinyjs::hide(id = "mainplot-plot") + shinyjs::show(id = "maintable-table") + shinyjs::show( + id = "download-export", + anim = TRUE, + animType = "fade", + time = 1 + ) + imageInfos <- prepareImageListImage(input = input, image_list = image_list) + 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.") + } else { + df <- pastclim::location_series( + x = locations, + bio_variables = imageInfos$variable, + dataset = "custom", + path_to_nc = path + ) + # Not sure if time column is always called time_bp. If not we need a different approach for filtering. + df <- df[df$time_bp >= min(input[["time_range-slider"]]) & + df$time_bp <= max(input[["time_range-slider"]]), ] + df$name <- NULL + table_data(df) + tableServer( + id = "maintable", + df = df + ) + } + }) %>% + bindEvent(input[["display_table-button"]], + ignoreInit = TRUE + ) +} diff --git a/man/observeShowTable.Rd b/man/observeShowTable.Rd new file mode 100644 index 0000000..179e870 --- /dev/null +++ b/man/observeShowTable.Rd @@ -0,0 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/03-tableModule.R +\name{observeShowTable} +\alias{observeShowTable} +\title{Observer to show table when display button is clicked} +\usage{ +observeShowTable(input, output, session, image_list, table_data) +} +\arguments{ +\item{input}{input object from server function} + +\item{output}{output object from server function} + +\item{session}{session from server function} + +\item{image_list}{reactive image list} + +\item{table_data}{reactive table data} +} +\description{ +Observer to show table when display button is clicked +} diff --git a/man/tableServer.Rd b/man/tableServer.Rd new file mode 100644 index 0000000..95e8628 --- /dev/null +++ b/man/tableServer.Rd @@ -0,0 +1,16 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/03-tableModule.R +\name{tableServer} +\alias{tableServer} +\title{Server function of table module} +\usage{ +tableServer(id, df) +} +\arguments{ +\item{id}{id of module} + +\item{df}{data frame to be displayed in table} +} +\description{ +Server function of table module +} diff --git a/man/tableUI.Rd b/man/tableUI.Rd new file mode 100644 index 0000000..cbb7ec2 --- /dev/null +++ b/man/tableUI.Rd @@ -0,0 +1,14 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/03-tableModule.R +\name{tableUI} +\alias{tableUI} +\title{UI function of table module} +\usage{ +tableUI(id) +} +\arguments{ +\item{id}{id of module} +} +\description{ +UI function of table module +}