Skip to content

Commit

Permalink
time plot table (#23)
Browse files Browse the repository at this point in the history
* time plot table

* renaming and default latitude longitude

* apply dataExport from shinyTools, remove code (#24)

---------

Co-authored-by: Antonia Runge <[email protected]>
  • Loading branch information
f-lukas and arunge authored Mar 6, 2024
1 parent a0428a4 commit 3bd286e
Show file tree
Hide file tree
Showing 13 changed files with 253 additions and 14 deletions.
5 changes: 3 additions & 2 deletions 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.2.0
Version: 24.3.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 @@ -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
Expand Down
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
10 changes: 10 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion R/00-Namespace.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
22 changes: 21 additions & 1 deletion R/01-mapPanelModule.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
)
)
),
Expand All @@ -36,7 +42,8 @@ mapPanelUI <- function(id) {
fluidRow(
column(12,
align = "center",
plotUI(id = ns("mainplot"))
plotUI(id = ns("mainplot")),
tableUI(id = ns("maintable"))
)
)
)
Expand All @@ -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",
Expand Down Expand Up @@ -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"]]
Expand Down
39 changes: 38 additions & 1 deletion R/02-createVariableSelectionInputs.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ createVariableSelectionInputs <- function(id) {
c(1, 2),
c(
"Single Map",
"Time plot"
"Time data"
)
)
)
Expand All @@ -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")
)
)
)
)
))
)
}
43 changes: 42 additions & 1 deletion R/02-observeEnableActionButton.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
7 changes: 0 additions & 7 deletions R/02-observeShowAndHideInputs.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
4 changes: 3 additions & 1 deletion R/02-observeShowPlot.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
79 changes: 79 additions & 0 deletions R/03-tableModule.R
Original file line number Diff line number Diff line change
@@ -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
)
}
22 changes: 22 additions & 0 deletions man/observeShowTable.Rd

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

16 changes: 16 additions & 0 deletions man/tableServer.Rd

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

14 changes: 14 additions & 0 deletions man/tableUI.Rd

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

0 comments on commit 3bd286e

Please sign in to comment.