Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Project object assignment #23

Merged
merged 42 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
06caa95
move global, server, ui in app.R file
hypebright Apr 16, 2024
1e05c13
move to `www` folder
hypebright Apr 16, 2024
05eb7d1
change `proj_obj` to be used in `r`
hypebright Apr 16, 2024
7fa0309
docs: add `r` and `proj_obj` as args
hypebright Apr 16, 2024
c08a290
source correct files
hypebright Apr 16, 2024
6c2e68b
use `get_proj` instead of `create_proj`
hypebright Apr 16, 2024
fde9040
use correct wd + introduce `this_wd` + rework overview
hypebright Apr 16, 2024
ec607b9
get proj from correct location
hypebright Apr 16, 2024
05a6b68
formatting
hypebright Apr 16, 2024
edc9507
change paths + update object after model run
hypebright Apr 17, 2024
e5d336f
move creation of temp folder to run_shinymixr
hypebright Apr 17, 2024
5c65439
change file path
hypebright Apr 17, 2024
1902e77
remove nlmixr + bump version
hypebright Apr 23, 2024
617cc83
docs: proj_obj
hypebright Apr 23, 2024
1f76758
declare record_test
hypebright Apr 23, 2024
be8acd9
very wip: change locations
hypebright Apr 23, 2024
778b983
point to correct folder
hypebright Apr 30, 2024
b888893
fix LICENSE warning
hypebright Apr 30, 2024
a848647
move non standard directories to /inst
hypebright Apr 30, 2024
d2bedc2
add pkgdown files
hypebright Apr 30, 2024
5e3061c
fix found if() conditions comparing class() to string
hypebright Apr 30, 2024
24f3209
import magrittr, stats, utils
hypebright Apr 30, 2024
c8ed35c
change location of exportTestValues
hypebright Apr 30, 2024
2550f31
debug test
hypebright Apr 30, 2024
c26e8f7
remove unused code (inputlist$attrl is always FALSE)
hypebright Apr 30, 2024
4848044
explicitly declare imports from shiny and nlmixr2
hypebright Apr 30, 2024
23dd2fc
correctly get proj_obj
hypebright Apr 30, 2024
ff86123
remove `attrl` as not used
hypebright Apr 30, 2024
20177aa
replace dataIn global assignment
hypebright Apr 30, 2024
6bfc2c3
replace deprecated fun.y with fun
hypebright Apr 30, 2024
9cd89ff
remove print statements
hypebright Apr 30, 2024
7b4cd30
remove data assignment to global env
hypebright Apr 30, 2024
6b73e31
add CRAN comments
hypebright Apr 30, 2024
e1d63fb
properly rename Dashboard to lowercase
hypebright Apr 30, 2024
9be5cc5
properly rename Other to lowercase
hypebright Apr 30, 2024
321b583
increase timeout
hypebright Apr 30, 2024
7b49c56
skip test on CI
hypebright Apr 30, 2024
f9a2d71
get folder structure right and better way to run app
RichardHooijmaijers May 6, 2024
707acf1
changes for folder structure mainly for wd
RichardHooijmaijers May 6, 2024
f58b8f0
fix: typo
hypebright May 7, 2024
84528e2
Cleaned code from unnecessary comments
RichardHooijmaijers May 14, 2024
3e3c44e
Merge branch 'proj-obj-assignment' of https://github.com/RichardHooij…
RichardHooijmaijers May 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
^.*\.Rproj$
^\.Rproj\.user$
^\.github$
^\.vscode$
^LICENSE\.md$
^_pkgdown\.yml$
^pkgdown$
^docs$
^cran-comments\.md$
13 changes: 7 additions & 6 deletions DESCRIPTION

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why w need magrittr as depend? Seems only %>% is used and is imported in NAMESPACE, right? Could consider using the base R pipe |> for this as it only occurs once in the entire code.
was wondering about the license file, saw LICENCE.md is new. Is it default behavior to ad such a file , e.g. is this not apparent when MIT is specified?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RichardHooijmaijers any packages used in the NAMESPACE must be listed in one of Imports or Depends. We can move it to Imports instead. Using the base pipe is a good idea, but you must be aware of your audience since this reduces backwards compatibility (as it also makes the package only compatibility with R >= 4.1). If that's not a problem I would replace it.

As per R CMD check, we needed the LICENSE.md file. It is not send to CRAN though, it is in .Rbuildignore. You can read more about that here: https://r-pkgs.org/license.html#key-files

Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
Package: shinyMixR
Title: Shiny dashboard interface for nlmixr and nlmixr2
Version: 0.4.0
Title: Interactive 'shiny' Dashboard for 'nlmixr2'
Version: 0.5.0
Authors@R: c(person("Richard", "Hooijmaijers", email = "richardhooijmaijers@gmail.com", role = c("aut", "cre","cph")),
person("Teun", "Post", email = "teunpost@gmail.com",role = c("aut","cph")),
person("LAPP Consultants",email = "info@lapp.nl", role=c("fnd","cph")),
person("Matthew Fidler",role=c("ctb")))
Author: Richard Hooijmaijers
Maintainer: Richard Hooijmaijers <richardhooijmaijers@gmail.com>
Description: The package is developed as an interface for the nlmixr and nlmixr2 package. Furthermore additional functions
are included to work with the nlmixr package through the command line
Description: An interface for the 'nlmixr2' package. Furthermore additional functions
are included to work with the 'nlmixr2' package through the command line.
Depends:
R (>= 3.5.0),
shiny,
ggplot2
ggplot2,
magrittr
Imports:
gridExtra,
collapsibleTree,
Expand All @@ -37,7 +38,7 @@ Suggests:
knitr,
rmarkdown,
rlang
License: MIT+LICENSE
License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.2.3
Expand Down
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# MIT License

Copyright (c) 2024 shinyMixR authors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
54 changes: 54 additions & 0 deletions NAMESPACE

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had some issues with this one... I wanted to add nlmixr2 as import. I was hoping that when running document() it was automatically added to NAMESPACE. This was not the case, so I added it manually, but was removed when running document again. I guess I am doing something wrong here but like to briefly discuss this issue (noticed you added manual imports as well, right?)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RichardHooijmaijers the NAMESPACE file should never be edited manually! If you want it to end up there, you need to include it in the roxygen comments of the function that uses the function (at least once in one of your functions), and then run devtools::document(). Alternatively, if you have things that need to be imported "globally", you can use the shinyMixR-package.R file for that. If you add new importFrom statements there, and run devtools::document(), they also ed up in NAMESPACE.

Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,58 @@ export(update_inits)
import(bs4Dash)
import(ggplot2)
import(gridExtra)
importFrom(magrittr,"%>%")
importFrom(shiny,HTML)
importFrom(shiny,NS)
importFrom(shiny,br)
importFrom(shiny,checkboxGroupInput)
importFrom(shiny,checkboxInput)
importFrom(shiny,conditionalPanel)
importFrom(shiny,div)
importFrom(shiny,em)
importFrom(shiny,eventReactive)
importFrom(shiny,exportTestValues)
importFrom(shiny,fluidRow)
importFrom(shiny,hr)
importFrom(shiny,icon)
importFrom(shiny,insertUI)
importFrom(shiny,isTruthy)
importFrom(shiny,isolate)
importFrom(shiny,modalDialog)
importFrom(shiny,moduleServer)
importFrom(shiny,numericInput)
importFrom(shiny,observe)
importFrom(shiny,observeEvent)
importFrom(shiny,plotOutput)
importFrom(shiny,radioButtons)
importFrom(shiny,reactive)
importFrom(shiny,reactivePoll)
importFrom(shiny,reactiveVal)
importFrom(shiny,reactiveValues)
importFrom(shiny,reactiveValuesToList)
importFrom(shiny,removeModal)
importFrom(shiny,removeUI)
importFrom(shiny,renderPlot)
importFrom(shiny,renderPrint)
importFrom(shiny,renderText)
importFrom(shiny,req)
importFrom(shiny,runApp)
importFrom(shiny,selectInput)
importFrom(shiny,showModal)
importFrom(shiny,sliderInput)
importFrom(shiny,span)
importFrom(shiny,tabPanel)
importFrom(shiny,tagList)
importFrom(shiny,tags)
importFrom(shiny,textInput)
importFrom(shiny,updateSelectInput)
importFrom(shiny,updateSliderInput)
importFrom(shiny,updateTabsetPanel)
importFrom(shiny,updateTextInput)
importFrom(shiny,verbatimTextOutput)
importFrom(stats,na.omit)
importFrom(stats,setNames)
importFrom(utils,getParseData)
importFrom(utils,installed.packages)
importFrom(utils,read.csv)
importFrom(utils,tail)
9 changes: 9 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# shinyMixR 0.5

This version is a preview version of the package. The main changes are:

- Refactoring of the code to remove global assignments and implement use of reactiveValues.
- Added codecoverage to the package.
- Added a new testing structure to the package including `shinytest2` for automated testing of the app.
- Improved documentation to prepare for CRAN submission.

# shinyMixR 0.4

Within this version some updates have been implemented, see below the most important changes:
Expand Down
17 changes: 11 additions & 6 deletions R/create_proj.r

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to revise this folder structure. In the end we need the subfolders "analysis", "data", etc. directly in loc. Noticed the difficulties with this folder structure and found that this is basically caused by the fact that the app was placed in the directory structure, this makes setting the required wd difficult/impossible. Because we don't want the app files in the directory structure, I made a completely new version of run_shinymixr. This now works with the folder structure and makes everything a lot cleaner
I changed this function also, to reflect mostly the original version

Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,20 @@
#' create_proj()
#' }
create_proj <- function(loc=".", overwrite=FALSE){

loc <- paste0(loc, "/shinyMixR/app")

if(!dir.exists(loc)) dir.create(loc, recursive = TRUE)

# First create the folder structure
dirs <- paste0(loc,c("/analysis","/data","/models","/shinyMixR","/scripts"))
dirs <- paste0(loc, c("/analysis","/data","/models","/shinyMixR","/scripts"))
if(!all(dirs%in%list.files(loc,full.names = TRUE))){
sapply(dirs,dir.create,showWarnings = FALSE,recursive=TRUE)
# Now place in some default models and data
if(!file.exists(paste0(loc,"/models/run1.r")) | overwrite) file.copy(paste0(system.file(package = "shinyMixR"),"/Other/run1.r"),paste0(loc,"/models/run1.r"))
if(!file.exists(paste0(loc,"/data/theo_sd.rds")) | overwrite) file.copy(paste0(system.file(package = "shinyMixR"),"/Other/theo_sd.rds"),paste0(loc,"/data/theo_sd.rds"))
if(!file.exists(paste0(loc,"/scripts/eta.plot.r")) | overwrite) file.copy(paste0(system.file(package = "shinyMixR"),"/Other/eta.plot.r"),paste0(loc,"/scripts/eta.plot.r"))
if(!file.exists(paste0(loc,"/scripts/vpc.plot.r")) | overwrite) file.copy(paste0(system.file(package = "shinyMixR"),"/Other/vpc.plot.r"),paste0(loc,"/scripts/vpc.plot.r"))
if(!file.exists(paste0(loc,"/scripts/combined.results.html.r")) | overwrite) file.copy(paste0(system.file(package = "shinyMixR"),"/Other/combined.results.html.r"),paste0(loc,"/scripts/combined.results.html.r"))
if(!file.exists(paste0(loc,"/models/run1.r")) | overwrite) file.copy(paste0(system.file(package = "shinyMixR"),"/other/run1.r"),paste0(loc,"/models/run1.r"))
if(!file.exists(paste0(loc,"/data/theo_sd.rds")) | overwrite) file.copy(paste0(system.file(package = "shinyMixR"),"/other/theo_sd.rds"),paste0(loc,"/data/theo_sd.rds"))
if(!file.exists(paste0(loc,"/scripts/eta.plot.r")) | overwrite) file.copy(paste0(system.file(package = "shinyMixR"),"/other/eta.plot.r"),paste0(loc,"/scripts/eta.plot.r"))
if(!file.exists(paste0(loc,"/scripts/vpc.plot.r")) | overwrite) file.copy(paste0(system.file(package = "shinyMixR"),"/other/vpc.plot.r"),paste0(loc,"/scripts/vpc.plot.r"))
if(!file.exists(paste0(loc,"/scripts/combined.results.html.r")) | overwrite) file.copy(paste0(system.file(package = "shinyMixR"),"/other/combined.results.html.r"),paste0(loc,"/scripts/combined.results.html.r"))
}
}
28 changes: 14 additions & 14 deletions R/exploreplot.r
hypebright marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ exploreplot <- function(inputlist){

# take into account that colour is used to map colour/fill and shape is used to map shape and linetype
inputlist$attrl <- FALSE
if(inputlist$attrl==TRUE) {ggstr <- "dataIn <- assign_attr(dataIn,attrl)"}else{ggstr <- NULL} # paste(ggstr,"+\n ",lay1)
if(inputlist$subset=="" & inputlist$nondups=="") ggstr <- paste0(ggstr,"\n","ggplot(dataIn)")
if(inputlist$subset=="" & inputlist$nondups!="") ggstr <- paste0(ggstr,"\n","ggplot(subset(dataIn, !duplicated(",inputlist$nondups,")))")
if(inputlist$subset!="" & inputlist$nondups=="") ggstr <- paste0(ggstr,"\n","ggplot(subset(dataIn,",inputlist$subset,"))")
if(inputlist$subset!="" & inputlist$nondups!="") ggstr <- paste0(ggstr,"\n","ggplot(subset(dataIn, !duplicated(",inputlist$nondups,") & ",inputlist$subset,"))")
ggstr <- NULL
if(inputlist$subset=="" & inputlist$nondups=="") ggstr <- paste0(ggstr,"\n","ggplot(r$dataIn)")
if(inputlist$subset=="" & inputlist$nondups!="") ggstr <- paste0(ggstr,"\n","ggplot(subset(r$dataIn, !duplicated(",inputlist$nondups,")))")
if(inputlist$subset!="" & inputlist$nondups=="") ggstr <- paste0(ggstr,"\n","ggplot(subset(r$dataIn,",inputlist$subset,"))")
if(inputlist$subset!="" & inputlist$nondups!="") ggstr <- paste0(ggstr,"\n","ggplot(subset(r$dataIn, !duplicated(",inputlist$nondups,") & ",inputlist$subset,"))")

addlay <- function(ageom,ayval,axval,agroup,acolour,ashape,asize,alabel,astats,afcol,afsize,afalph){
if(astats!='[empty]' & ageom%in%c("boxplot","bar","histogram","smooth","jitter","text")) stop("Stats can only be displayed as 'line' or 'point'")
Expand Down Expand Up @@ -65,11 +65,11 @@ exploreplot <- function(inputlist){
aess <- paste(paste(names(aess),aess,sep="="),collapse=", ")

if(astats%in%c("mean","median")){
lay <- paste0("stat_summary","(aes(",aess,"), fun.y=",astats,", geom='", ageom,"', ",argm,")")
lay <- paste0("stat_summary","(aes(",aess,"), fun=",astats,", geom='", ageom,"', ",argm,")")
}else if(astats=="mean (SD)"){
lay <- paste0("stat_summary","(aes(",aess,"), fun.y=mean, fun.ymin=function(x) mean(x) - sd(x), fun.ymax=function(x) mean(x) + sd(x), geom='errorbar', width = 0.2, ",argm,")")
lay <- paste0("stat_summary","(aes(",aess,"), fun=mean, funmin=function(x) mean(x) - sd(x), funmax=function(x) mean(x) + sd(x), geom='errorbar', width = 0.2, ",argm,")")
}else if(astats=="median (5-95th perc.)"){
lay <- paste0("stat_summary","(aes(",aess,"), fun.y=median, fun.ymin=function(x) quantile(x,0.05), fun.ymax=function(x) quantile(x,0.95), geom='errorbar', width = 0.2, ",argm,")")
lay <- paste0("stat_summary","(aes(",aess,"), fun=median, funmin=function(x) quantile(x,0.05), funmax=function(x) quantile(x,0.95), geom='errorbar', width = 0.2, ",argm,")")
}else{
lay <- paste0("geom_",ageom,"(aes(",aess,"), ",argm,")")
}
Expand Down Expand Up @@ -105,9 +105,9 @@ exploreplot <- function(inputlist){
if(inputlist$facet1!='[empty]' & inputlist$facet2!='[empty]' & inputlist$facet3!='[empty]') fct <- paste0("~",inputlist$facet1,"+",inputlist$facet2,"+",inputlist$facet3)
if(is.na(inputlist$ncol)){ncols <- NULL}else{ncols <- inputlist$ncol}
if(!is.null(fct)) add <- c(add,fac=paste0("facet_wrap(",fct,",scales='",inputlist$facetsc,"', labeller=label_both, ncol=",ncols,")"))

xlb <- ifelse(inputlist$xlab!="",inputlist$xlab, ifelse(inputlist$attrl==TRUE && !is.null(attrl) && !is.null(attrl[[inputlist$Xval1]]$label),attrl[[inputlist$Xval1]]$label,inputlist$Xval1))
ylb <- ifelse(inputlist$ylab!="",inputlist$ylab, ifelse(inputlist$attrl==TRUE && !is.null(attrl) && !is.null(attrl[[inputlist$Yval1]]$label),attrl[[inputlist$Yval1]]$label,inputlist$Yval1))
xlb <- ifelse(inputlist$xlab != "", inputlist$xlab, inputlist$Xval1)
ylb <- ifelse(inputlist$ylab != "", inputlist$ylab, inputlist$Yval1)
if(ylb=="[empty]") ylb <- "Count" # y label could only be empty in case of histogram, otherwise y variable should be selected
#if(inputlist$xlab!='') add <- c(add,xlab=paste0("xlab('",inputlist$xlab,"')"))
#if(inputlist$ylab!='') add <- c(add,ylab=paste0("ylab('",inputlist$ylab,"')"))
Expand All @@ -116,9 +116,9 @@ exploreplot <- function(inputlist){
if(inputlist$ptitle!='') add <- c(add,ggtitle=paste0("ggtitle('",inputlist$ptitle,"')"))

# set manual color scale or fill in case one of the layers has colors (AND it is set as factor!!)
cond1 <- inputlist$colour1!='[empty]' & grepl(paste0("factor\\(dataIn.",inputlist$colour1),inputlist$precode)
cond2 <- inputlist$colour2!='[empty]' & grepl(paste0("factor\\(dataIn.",inputlist$colour2),inputlist$precode)
cond3 <- inputlist$colour3!='[empty]' & grepl(paste0("factor\\(dataIn.",inputlist$colour3),inputlist$precode)
cond1 <- inputlist$colour1!='[empty]' & grepl(paste0("factor\\(r$dataIn.",inputlist$colour1),inputlist$precode)
cond2 <- inputlist$colour2!='[empty]' & grepl(paste0("factor\\(r$dataIn.",inputlist$colour2),inputlist$precode)
cond3 <- inputlist$colour3!='[empty]' & grepl(paste0("factor\\(r$dataIn.",inputlist$colour3),inputlist$precode)
cond4 <- inputlist$colour1!='[empty]' & inputlist$geoms1%in%c("boxplot","bar","histogram")
cond5 <- inputlist$colour2!='[empty]' & inputlist$geoms2%in%c("boxplot","bar","histogram")
cond6 <- inputlist$colour3!='[empty]' & inputlist$geoms3%in%c("boxplot","bar","histogram")
Expand Down
25 changes: 9 additions & 16 deletions R/get_proj.r

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See remark create_proj, I think the folder structure should be different. Will propose some changes here

Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,22 @@
#' proj <- get_proj()
#' }
get_proj <- function(projloc=".",geteval=TRUE){

# Read in models and place in result objects
dir.create(paste0(projloc,"/shinyMixR"),showWarnings = FALSE,recursive = TRUE)
mdln <- normalizePath(list.files(paste0(projloc,"/models"),pattern="run[[:digit:]]*\\.[r|R]",full.names = TRUE))
dir.create(paste0(projloc,"/shinyMixR/app/shinyMixR"),showWarnings = FALSE,recursive = TRUE)
mdln <- normalizePath(list.files(paste0(projloc,"/shinyMixR/app/models"),pattern="run[[:digit:]]*\\.[r|R]",full.names = TRUE))
mdlnb <- sub("\\.[r|R]","",basename(mdln))
sumres <- normalizePath(list.files(paste0(projloc,"/shinyMixR"),pattern="run[[:digit:]]*\\.ressum\\.rds",full.names = TRUE))
sumres <- normalizePath(list.files(paste0(projloc,"/shinyMixR/app/shinyMixR"),pattern="run[[:digit:]]*\\.ressum\\.rds",full.names = TRUE))
sumresi <- file.info(sumres)
summdli <- file.info(mdln)

# read in data folder (only in case objects are not yet present)
datf <- list.files(paste0(projloc,"/data"))
datf <- list.files(paste0(projloc,"/shinyMixR/app/data"))
grepd <- " |^[[:digit:]]|\\!|\\#|\\$|\\%|\\&|\\'|\\(|\\)|\\-|\\;|\\=|\\@|\\[|\\]|\\^\\`\\{\\|\\}"
if(any(grepl(grepd,datf))) warning("Data files with special characters found, take into acount that models that use these can crash")
# not relevant to read all data for running nlmixr in separate session (should be loaded in this session!)
lapply(list.files(paste0(projloc,"/data"),full.names = TRUE),function(x){
if(!grepl(grepd,x) & !exists(sub("\\.rds$|\\.csv$","",basename(x),ignore.case = TRUE),envir=.GlobalEnv)){
if(grepl("\\.rds$",x,ignore.case = TRUE)) assign(sub("\\.rds$","",basename(x),ignore.case = TRUE),readRDS(x),pos = .GlobalEnv)
if(grepl("\\.csv$",x,ignore.case = TRUE)) assign(sub("\\.csv$","",basename(x),ignore.case = TRUE),read.csv(x),pos = .GlobalEnv)
}
})

# Read in models and results
if(!file.exists(paste0(projloc,"/shinyMixR/project.rds"))){
if(!file.exists(paste0(projloc,"/shinyMixR/app/shinyMixR/project.rds"))){
mdls <- lapply(mdln,list)
names(mdls) <- sub("\\.[r|R]","",basename(mdln))
if(length(mdln)==0){
Expand All @@ -52,7 +45,7 @@ get_proj <- function(projloc=".",geteval=TRUE){
for(i in sumres) mdls[[sub("\\.ressum\\.rds","",basename(i))]]$results <- readRDS(i)
mdls$meta <- list(lastrefresh=Sys.time())
}else{
mdls <- readRDS(paste0(projloc,"/shinyMixR/project.rds"))
mdls <- readRDS(paste0(projloc,"/shinyMixR/app/shinyMixR/project.rds"))
# for the list with models, check if new models are available or old models are deleted
# and if models are updated after last refresh:
# inproj <- unlist(sapply(mdls[names(mdls)[names(mdls)!="meta"]],"[",1))
Expand Down Expand Up @@ -92,6 +85,6 @@ get_proj <- function(projloc=".",geteval=TRUE){
chk <- chk[which(chk$mdlsv>chk$ressv),]
#if(nrow(chk)>0) noret <- apply(chk,1,function(x) cat("Be aware that model is saved after results for",x['mdl'],"\n"))

saveRDS(mdls,file=paste0(projloc,"/shinyMixR/project.rds"))
saveRDS(mdls,file=paste0(projloc,"/shinyMixR/app/shinyMixR/project.rds"))
return(mdls)
}
20 changes: 10 additions & 10 deletions R/module_dataexplore.R
Original file line number Diff line number Diff line change
Expand Up @@ -148,23 +148,23 @@ module_dataexplore_server <- function(id, r) {
# Adapt model list based on selected project location
observeEvent(r$active_tab,{
if(r$active_tab=="expl"){
updateSelectInput(session, "mdls", choices = names(get("proj_obj",pos = .GlobalEnv))[names(get("proj_obj",pos = .GlobalEnv))!="meta"],selected=input$mdls)
updateSelectInput(session, "mdls", choices = names(r$proj_obj)[names(r$proj_obj)!="meta"],selected=input$mdls)
}
},ignoreInit=TRUE)

# Select different model (for now assign in global environment)
# Select different model (store in reactive values object)
updfunc <- function(){
if(input$use_input){
assign("dataIn",try(readRDS(paste0("shinyMixR/",input$mdls[1],".res.rds"))$origData),envir=.GlobalEnv)
r$dataIn <- try(readRDS(paste0("shinyMixR/",input$mdls[1],".res.rds"))$origData)
}else{
assign("dataIn",try(as.data.frame(readRDS(paste0("shinyMixR/",input$mdls[1],".res.rds")))),envir=.GlobalEnv)
r$dataIn <- try(as.data.frame(readRDS(paste0("shinyMixR/",input$mdls[1],".res.rds"))))
}
if(!"try-error"%in%class(dataIn)){
if(!"try-error" %in% class(r$dataIn)){
set1 <- paste0(c("Xval","Yval","group","colour","shape","size","label","facet"),rep(1:3,each=8))
set1 <- lapply(set1,function(x) {
updateSelectInput(session,x,choices=c("[empty]",names(dataIn)),selected=ifelse(input[[x]]=="","[empty]",input[[x]]))
updateSelectInput(session,x,choices=c("[empty]",names(r$dataIn)),selected=ifelse(input[[x]]=="","[empty]",input[[x]]))
})
updateSelectInput(session,"nondups",choices=c("",names(dataIn)),selected="")
updateSelectInput(session,"nondups",choices=c("",names(r$dataIn)),selected="")
}
}
observeEvent(input$mdls,{updfunc()},ignoreInit=TRUE)
Expand Down Expand Up @@ -207,9 +207,9 @@ module_dataexplore_server <- function(id, r) {
upDT <- eventReactive(input$maketbl,{
if(!is.null(input$mdls)){
if(!is.null(input$precode) && input$precode!="") eval(parse(text=input$precode))
if(!is.null(input$subset) && input$subset!="") eval(parse(text=paste0("dataIn <- subset(dataIn,",input$subset,")")))
if(!is.null(input$nondups) && input$nondups!="") eval(parse(text=paste0("dataIn <- subset(dataIn, !duplicated(",input$nondups,"))")))
dataIn
if(!is.null(input$subset) && input$subset!="") eval(parse(text=paste0("r$dataIn <- subset(r$dataIn,",input$subset,")")))
if(!is.null(input$nondups) && input$nondups!="") eval(parse(text=paste0("r$dataIn <- subset(r$dataIn, !duplicated(",input$nondups,"))")))
r$dataIn
}
})
output$tableout <- DT::renderDT(upDT(),options=list(scrollX=TRUE,pageLength=100,lengthMenu=c(10,100,1000,10000))) # Show entire dataset
Expand Down
Loading
Loading