Skip to content

Commit

Permalink
Merge pull request #80 from habitus-eu/issue66_replace_hardcodedpath
Browse files Browse the repository at this point in the history
Give user control over location conda environment
  • Loading branch information
vincentvanhees authored Jun 30, 2023
2 parents f86ee70 + c0322ac commit 651a7cb
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 66 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: HabitusGUI
Title: R Shiny App for Processing Behavioural Data
Description: Shiny app to ease processing behavioural data with research software such as GGIR, activityCounts, PALMSpy,and palmsplusr.
Version: 0.1.6
Date: 2022-03-15
Version: 0.1.8
Date: 2022-06-30
Authors@R:
c(person(given = "Vincent",
family = "van Hees",
Expand Down
7 changes: 4 additions & 3 deletions R/PALMSpyshiny.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@
#'
#' @param outputdir Path to output directory
#' @param gpsdir Path to GPS files
#' @param envConda character to specify path conda environment used for PALMSpy
#' @param count_file_location Path to count files
#' @return no object is returned, only a new file is created in the output directory
#' @export

PALMSpyshiny = function(outputdir, gpsdir, count_file_location) {
PALMSpyshiny = function(outputdir, gpsdir, count_file_location, envConda = "~/miniconda3/bin/conda") {
if (tolower(Sys.getenv("USERNAME")) %in% c("ucloud", "", "shiny") == FALSE) {
#assuming palmspy is in a local conda environment"
# assuming unbuffer is available in Ubuntu(apt install expect)
palmspypath = " /home/vincent/miniconda3/bin/conda run --no-capture-output -n palmspy "
palmspypath = paste0(envConda, " run --no-capture-output -n palmspy ")
} else {
#assuming palmspy is directly available from command line (ucloud)
palmspypath = ""
}
basecommand = paste0("cd ",outputdir, "; nohup unbuffer", palmspypath, " palmspy --gps-path ", gpsdir,
basecommand = paste0("cd ",outputdir, "; nohup unbuffer ", palmspypath, " palmspy --gps-path ", gpsdir,
" --acc-path ", count_file_location,
" --config-file ", paste0(outputdir, "/config.json"),
" > ", outputdir, "/PALMSpy.log 2>&1 &")
Expand Down
12 changes: 7 additions & 5 deletions R/myApp.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#' myApp
#'
#' @param homedir character to specify home directory
#' @param homedir character to specify path to home directory
#' @param envConda character to specify path conda environment used for PALMSpy
#' @param ... No input needed, function runs the app
#' @return no object is returned, just an app
#' @import shiny
Expand All @@ -16,7 +17,7 @@

# create temp log file

myApp <- function(homedir=getwd(), ...) {
myApp <- function(homedir=getwd(), envConda = "~/miniconda3/bin/conda", ...) {
stdout_GGIR_tmp <- tempfile(fileext = ".log")
stdout_palmsplusr_tmp <- tempfile(fileext = ".log")
stdout_PALMSpy_tmp <- tempfile(fileext = ".log")
Expand Down Expand Up @@ -965,13 +966,14 @@ overflow-y:scroll; max-height: 300px; background: ghostwhite;}")),


# # Start PALMSpy
x_palmspy <- r_bg(func = function(PALMSpyshiny, outputdir, gpsdir, count_file_location) {
PALMSpyshiny(outputdir, gpsdir, count_file_location)
x_palmspy <- r_bg(func = function(PALMSpyshiny, outputdir, gpsdir, count_file_location, envConda) {
PALMSpyshiny(outputdir, gpsdir, count_file_location, envConda)
},
args = list(PALMSpyshiny = PALMSpyshiny,
outputdir = global$data_out,
gpsdir = global$gps_in,
count_file_location = count_file_location),
count_file_location = count_file_location,
envConda = envConda),
stdout = "",
stderr = "")

Expand Down
13 changes: 9 additions & 4 deletions UCloud_files/ucloud_HabitusGUI_installation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,17 @@ sudo apt-get update && sudo apt-get install -y \
libgdal-dev \
libudunits2-dev

R -e 'install.packages(c("shinyFiles", "shiny", "GGIR", "jsonlite", "DT", "waiter"), repos = "https://packagemanager.rstudio.com/cran/__linux__/focal/latest", dependencies = TRUE)'
R -e 'install.packages(c("activityCounts", "remotes", "shinyjs", "dplyr", "magrittr"), repos = "https://packagemanager.rstudio.com/cran/__linux__/focal/latest", dependencies = TRUE)'
# Shiny dependencies
R -e 'install.packages(c("shinyFiles", "shiny", "jsonlite", "DT", "waiter", "bslib"), repos = "https://packagemanager.rstudio.com/cran/__linux__/focal/latest", dependencies = TRUE)'
# GGIR and its dependencies
R -e 'install.packages(c("GGIR", "actilifecounts", "ActCR", "GGIRread", "read.gt3x"), repos = "https://packagemanager.rstudio.com/cran/__linux__/focal/latest", dependencies = TRUE)'
# palmsplusr dependencies
R -e 'install.packages(c("remotes", "shinyjs", "dplyr", "magrittr"), repos = "https://packagemanager.rstudio.com/cran/__linux__/focal/latest", dependencies = TRUE)'
R -e 'install.packages(c("sf", "readr", "tidyr", "stringr", "sp", "raster", "lwgeom", "tidyverse"), repos = "https://packagemanager.rstudio.com/cran/__linux__/focal/latest", dependencies = TRUE)'
R -e 'remotes::install_github("rstudio/bslib", dependencies = TRUE)' # development version because CRAN version has bug that affects us
# palmsplusr itself
R -e 'remotes::install_github("vincentvanhees/palmsplusr", dependencies = TRUE)'
R -e 'remotes::install_github("habitus-eu/HabitusGUI", dependencies = TRUE)'
# The HabitusGUI itself
R -e 'remotes::install_github("habitus-eu/HabitusGUI", ref = "issue66_replace_hardcodedpath", dependencies = TRUE)'


# Assuming that app.R is in the same folder as this script
Expand Down
8 changes: 6 additions & 2 deletions inst/NEWS.Rd
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
\name{NEWS}
\title{News for Package \pkg{HabitusGUI}}
\newcommand{\cpkg}{\href{http://CRAN.R-project.org/package=#1}{\pkg{#1}}}

\section{Changes in version 0.1.8 (GitHub-only-release date: 30-06-2023)}{
\itemize{
\item Allowing package user to specify the local conda environment location needed for PALMSpy
\item Shiny state is saved and used if available when refreshing the app.
}
}
\section{Changes in version 0.1.7 (GitHub-only-release date: 01-05-2023)}{
\itemize{
\item Revised tsv file for GGIR configuration
\item Testfile for config GGIR updated
\item Now able to handle acc.metric in GGIR
\item HabitusGUI and use-case GGIR can now run again in Windows, this was broken ince 0.1.5 release
\item Shiny state is saved and used if available when refreshing the app.
}
}
\section{Changes in version 0.1.6 (GitHub-only-release date: 15-03-2023)}{
Expand Down
94 changes: 47 additions & 47 deletions inst/testfiles_palmsplusr/config_palmsplusr.csv
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
"context","name","formula","domain_field","after_conversion"
"palmsplus_field","weekday","dow < 6",FALSE,NA
"palmsplus_field","weekend","dow > 5",FALSE,NA
"palmsplus_field","indoors","iov == 3",FALSE,NA
"palmsplus_field","outdoors","iov == 1",FALSE,NA
"palmsplus_field","in_vehicle","iov == 2",FALSE,NA
"palmsplus_field","inserted","fixtypecode == 6",FALSE,NA
"palmsplus_field","pedestrian","tripmot == 1",FALSE,NA
"palmsplus_field","bicycle","tripmot == 2",FALSE,NA
"palmsplus_field","vehicle","tripmot == 3",FALSE,NA
"palmsplus_field","nonwear","activityintensity < 0",TRUE,NA
"palmsplus_field","wear","activityintensity >= 0",TRUE,NA
"palmsplus_field","sedentary","activityintensity == 0",TRUE,NA
"palmsplus_field","light","activityintensity == 1",TRUE,NA
"palmsplus_field","moderate","activityintensity == 2",TRUE,NA
"palmsplus_field","vigorous","activityintensity == 3",TRUE,NA
"palmsplus_field","mvpa","moderate + vigorous",TRUE,NA
"trajectory_field","mot","first(tripmot)",NA,FALSE
"trajectory_field","date","first(as.Date(datetime))",NA,FALSE
"trajectory_field","start","datetime[triptype==1]",NA,FALSE
"trajectory_field","end","datetime[triptype==4]",NA,FALSE
"trajectory_field","duration","as.numeric(difftime(end, start, units = ""secs"") + 30)",NA,FALSE
"trajectory_field","nonwear","sum(activityintensity < 0) * 15",NA,FALSE
"trajectory_field","wear","sum(activityintensity >= 0) * 15",NA,FALSE
"trajectory_field","sedentary","sum(activityintensity == 1) * 15",NA,FALSE
"trajectory_field","light","sum(activityintensity == 1) * 15",NA,FALSE
"trajectory_field","moderate","sum(activityintensity == 2) * 15",NA,FALSE
"trajectory_field","vigorous","sum(activityintensity == 3) * 15",NA,FALSE
"trajectory_field","mvpa","moderate + vigorous",NA,FALSE
"trajectory_field","length","as.numeric(st_length(geometry))",NA,TRUE
"trajectory_field","speed","(length / duration) * 3.6",NA,TRUE
"multimodal_field","duration","sum",NA,NA
"multimodal_field","nonwear","sum",NA,NA
"multimodal_field","wear","sum",NA,NA
"multimodal_field","sedentary","sum",NA,NA
"multimodal_field","light","sum",NA,NA
"multimodal_field","moderate","sum",NA,NA
"multimodal_field","vigorous","sum",NA,NA
"multimodal_field","mvpa","sum",NA,NA
"multimodal_field","length","sum",NA,NA
"multimodal_field","speed","mean",NA,NA
"palmsplus_domain","home","at_home",FALSE,NA
"palmsplus_domain","school","(!at_home & at_school)",FALSE,NA
"palmsplus_domain","transport","!at_home & !(at_school) & (pedestrian | bicycle | vehicle)",FALSE,NA
"palmsplus_domain","home_nbh","!at_home & !(at_school) & (!pedestrian & !bicycle & !vehicle) & at_home_nbh",FALSE,NA
"palmsplus_domain","school_nbh","!at_home & !(at_school) & (!pedestrian & !bicycle & !vehicle) & !(at_home_nbh) & at_school_nbh",FALSE,NA
"palmsplus_domain","other","!at_home & !(at_school) & (!pedestrian & !bicycle & !vehicle) & !(at_home_nbh) & !(at_school_nbh)",FALSE,NA
context,name,formula,domain_field,after_conversion
palmsplus_field,weekday,dow < 6,FALSE,NA
palmsplus_field,weekend,dow > 5,FALSE,NA
palmsplus_field,indoors,iov == 3,FALSE,NA
palmsplus_field,outdoors,iov == 1,FALSE,NA
palmsplus_field,in_vehicle,iov == 2,FALSE,NA
palmsplus_field,inserted,fixtypecode == 6,FALSE,NA
palmsplus_field,pedestrian,tripmot == 1,FALSE,NA
palmsplus_field,bicycle,tripmot == 2,FALSE,NA
palmsplus_field,vehicle,tripmot == 3,FALSE,NA
palmsplus_field,nonwear,activityintensity < 0,TRUE,NA
palmsplus_field,wear,activityintensity >= 0,TRUE,NA
palmsplus_field,sedentary,activityintensity == 0,TRUE,NA
palmsplus_field,light,activityintensity == 1,TRUE,NA
palmsplus_field,moderate,activityintensity == 2,TRUE,NA
palmsplus_field,vigorous,activityintensity == 3,TRUE,NA
palmsplus_field,mvpa,moderate + vigorous,TRUE,NA
trajectory_field,mot,first(tripmot),NA,FALSE
trajectory_field,date,first(as.Date(datetime)),NA,FALSE
trajectory_field,start,datetime[triptype==1],NA,FALSE
trajectory_field,end,datetime[triptype==4],NA,FALSE
trajectory_field,duration,"as.numeric(difftime(end, start, units = ""secs"") + 30)",NA,FALSE
trajectory_field,nonwear,sum(activityintensity < 0) * 15,NA,FALSE
trajectory_field,wear,sum(activityintensity >= 0) * 15,NA,FALSE
trajectory_field,sedentary,sum(activityintensity == 1) * 15,NA,FALSE
trajectory_field,light,sum(activityintensity == 1) * 15,NA,FALSE
trajectory_field,moderate,sum(activityintensity == 2) * 15,NA,FALSE
trajectory_field,vigorous,sum(activityintensity == 3) * 15,NA,FALSE
trajectory_field,mvpa,moderate + vigorous,NA,FALSE
trajectory_field,length,as.numeric(st_length(geometry)),NA,TRUE
trajectory_field,speed,(length / duration) * 3.6,NA,TRUE
multimodal_field,duration,sum,NA,NA
multimodal_field,nonwear,sum,NA,NA
multimodal_field,wear,sum,NA,NA
multimodal_field,sedentary,sum,NA,NA
multimodal_field,light,sum,NA,NA
multimodal_field,moderate,sum,NA,NA
multimodal_field,vigorous,sum,NA,NA
multimodal_field,mvpa,sum,NA,NA
multimodal_field,length,sum,NA,NA
multimodal_field,speed,mean,NA,NA
palmsplus_domain,home,at_home,TRUE,NA
palmsplus_domain,school,(!at_home & at_school),TRUE,NA
palmsplus_domain,transport,!at_home & !(at_school) & (pedestrian | bicycle | vehicle),TRUE,NA
palmsplus_domain,home_nbh,!at_home & !(at_school) & (!pedestrian & !bicycle & !vehicle) & at_home_nbh,TRUE,NA
palmsplus_domain,school_nbh,!at_home & !(at_school) & (!pedestrian & !bicycle & !vehicle) & !(at_home_nbh) & at_school_nbh,TRUE,NA
palmsplus_domain,other,!at_home & !(at_school) & (!pedestrian & !bicycle & !vehicle) & !(at_home_nbh) & !(at_school_nbh),TRUE,NA
9 changes: 8 additions & 1 deletion man/PALMSpyshiny.Rd

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

6 changes: 4 additions & 2 deletions man/myApp.Rd

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

0 comments on commit 651a7cb

Please sign in to comment.