From dcc6e82608ac7cf59e156bfe8cc2458875822094 Mon Sep 17 00:00:00 2001 From: Dony Indiarto Date: Mon, 24 Jun 2024 14:08:52 +0700 Subject: [PATCH] Update names --- DESCRIPTION | 6 ++--- ALSA.Rproj => LaSEM.Rproj | 0 NAMESPACE | 2 +- R/plot_raster_layers.R | 0 R/sm_suitability_analysis.R | 44 ++++++++++++++++++++++--------- man/{ALSA_app.Rd => LaSEM_app.Rd} | 8 +++--- 6 files changed, 40 insertions(+), 20 deletions(-) rename ALSA.Rproj => LaSEM.Rproj (100%) create mode 100644 R/plot_raster_layers.R rename man/{ALSA_app.Rd => LaSEM_app.Rd} (71%) diff --git a/DESCRIPTION b/DESCRIPTION index 420926b..1ceaf12 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,10 +1,10 @@ -Package: ALSA -Title: Agricultural Land Suitability Analysis (ALSA) +Package: LaSEM +Title: Land Suitability Evaluation Module (LaSEM) Version: 0.0.0.9000 Authors@R: person("Dony", "Indiarto", , "d.indiarto@cifor-icraf.org", role = c("aut", "cre"), comment = c(ORCID = "0000-0001-9546-8201")) -Description: The Agricultural Land Suitability Analysis (ALSA) is a modular R-based Shiny app for decision-support system for producing and sourcing agricultural commodities. The first version of the Shiny app aims for the suitability analysis for the biophysical factors. The application guides users in collecting and preparing data to visualize suitability maps of certain crops on an interactive map, thus bundling the workflows into a single, streamlined interface. The main feature of ALSA is its spatially-explicit functionality and streamlined interface which allows it to automatically evaluate land suitability based on biophysical factors of specific areas using the FAO framework. This application is built upon the theory of land evaluation and suitability assessment (i.e., FAO 1976, 2007). +Description: Land Suitability Evaluation Module (LaSEM) is a modular R-based Shiny app for decision-support system for producing land suitability maps of food, horticulture, and estate crop commodities. The first version of the Shiny app aims for the suitability analysis for the biophysical factors. The application guides users in collecting and preparing data to visualize suitability maps of certain crops on an interactive map, thus bundling the workflows into a single, streamlined interface. The main feature of LaSEM is its spatially-explicit functionality and streamlined interface which allows it to automatically evaluate land suitability based on biophysical factors of specific areas using the FAO framework. This application is built upon the theory of land evaluation and suitability assessment (i.e., FAO 1976, 2007). License: GPL (>= 3) Imports: dplyr, diff --git a/ALSA.Rproj b/LaSEM.Rproj similarity index 100% rename from ALSA.Rproj rename to LaSEM.Rproj diff --git a/NAMESPACE b/NAMESPACE index eec0961..df6df63 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,6 +1,6 @@ # Generated by roxygen2: do not edit by hand -export(ALSA_app) +export(LaSEM_app) export(classify_and_stack_suitability_factors) export(classify_suitability_predictors) export(concat_rasters) diff --git a/R/plot_raster_layers.R b/R/plot_raster_layers.R new file mode 100644 index 0000000..e69de29 diff --git a/R/sm_suitability_analysis.R b/R/sm_suitability_analysis.R index 51fbf8b..d086118 100644 --- a/R/sm_suitability_analysis.R +++ b/R/sm_suitability_analysis.R @@ -30,7 +30,7 @@ suitabilityAnalysisUI <- function(id) { ) ), tabsetPanel( - tabPanel("Suitability Map", leafletOutput(NS(id, "suitabilityMap"))), + tabPanel("Suitability Map", withSpinner(leafletOutput(NS(id, "suitabilityMap")))), tabPanel("Suitability Map by Factors", fluidRow( column(12, @@ -40,7 +40,10 @@ suitabilityAnalysisUI <- function(id) { ) ), tabPanel("Attribute Table", DTOutput(NS(id, "suitabilityPolygon"))), - tabPanel("Download Results", downloadButton(NS(id, "downloadResults"), "Download Results")) + tabPanel("Download Results", + downloadButton(NS(id, "downloadShapefile"), "Download Shapefile"), + downloadButton(NS(id, "downloadRaster"), "Download Raster"), + downloadButton(NS(id, "downloadTable"), "Download Attribute Table")) ) ) } @@ -223,25 +226,42 @@ suitabilityAnalysisServer <- function(id, submittedData) { datatable(suitability_polygon) }) - # Provide an option to download the suitability analysis results - output$downloadResults <- downloadHandler( + # Provide options to download different sets of files + output$downloadShapefile <- downloadHandler( filename = function() { - paste("suitability_results", Sys.Date(), ".zip", sep = "_") + paste("suitability_map", Sys.Date(), ".zip", sep = "_") }, content = function(file) { - # Save the suitability analysis results to a temporary directory + # Save the suitability map to a temporary directory tempdir <- tempdir() - - # Save the suitability map, polygon, and other results to the temporary directory + browser() suitability_map <- suitabilityResults()$suitability_polygon - write_sf(suitability_map, file.path(tempdir, "suitability_map.shp")) - - suitability_by_factors <- suitabilityResults()$suitability_by_factors - writeRaster(suitability_by_factors, file.path(tempdir, "suitability_by_factors.tif")) + st_write(suitability_map, file.path(tempdir, "suitability_map.shp"), + append = FALSE) # Zip the temporary directory and write it to the specified file zip(file, tempdir) } ) + + output$downloadRaster <- downloadHandler( + filename = function() { + paste("suitability_by_factors", Sys.Date(), ".tif", sep = "_") + }, + content = function(file) { + suitability_by_factors <- suitabilityResults()$suitability_by_factors + writeRaster(suitability_by_factors, file, overwrite = TRUE) + } + ) + + output$downloadTable <- downloadHandler( + filename = function() { + paste("suitability_attr", Sys.Date(), ".csv", sep = "_") + }, + content = function(file) { + suitability_attr <- suitabilityResults()$suitability_attr + write_csv(suitability_attr, file) + } + ) }) } diff --git a/man/ALSA_app.Rd b/man/LaSEM_app.Rd similarity index 71% rename from man/ALSA_app.Rd rename to man/LaSEM_app.Rd index e7b826a..7d5f1a0 100644 --- a/man/ALSA_app.Rd +++ b/man/LaSEM_app.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/app.R -\name{ALSA_app} -\alias{ALSA_app} -\title{Agricultural Land Suitability Analysis (ALSA) Shiny App} +\name{LaSEM_app} +\alias{LaSEM_app} +\title{Land Suitability Evaluation Module (LaSEM) Shiny App} \usage{ -ALSA_app(...) +LaSEM_app(...) } \arguments{ \item{...}{Additional arguments to pass to the Shiny app.}