Skip to content
Snippets Groups Projects
Unverified Commit 3480c5e4 authored by Todor Kondic's avatar Todor Kondic
Browse files

Add saving configuration

* R/shiny-ui-base.R(obsrv_e,validate,vol_f): New wrappers.

* R/shiny-ui-config.R(saveConfB): Change default filename and
  filetype.

* R/shiny-ui-config.R(input$saveConfB): New observer.
parent 8f592509
No related branches found
No related tags found
No related merge requests found
...@@ -592,3 +592,8 @@ read_setid <- function(fn,known,unk) { ...@@ -592,3 +592,8 @@ read_setid <- function(fn,known,unk) {
assertthat::assert_that(nrow(natmp)==0,msg=paste("The following IDs from set table have not been found in the compound table:","------",print_table(natmp),"------",sep = "\n")) assertthat::assert_that(nrow(natmp)==0,msg=paste("The following IDs from set table have not been found in the compound table:","------",print_table(natmp),"------",sep = "\n"))
tmp tmp
} }
write_conf <- function(conf,fn) {
yaml::write_yaml(x=conf,file=fn)
}
...@@ -16,7 +16,11 @@ react_v <- shiny::reactiveValues ...@@ -16,7 +16,11 @@ react_v <- shiny::reactiveValues
react_f <- shiny::reactive react_f <- shiny::reactive
react_e <- shiny::eventReactive react_e <- shiny::eventReactive
obsrv <- shiny::observe obsrv <- shiny::observe
obsrv_e <- shiny::observeEvent
vols <- shinyFiles::getVolumes vols <- shinyFiles::getVolumes
vol_f <- vols()
validate <- function(expr,msg) shiny::validate(need(expr,msg))
path2vol <- function(path) { path2vol <- function(path) {
## This function returns shinyFiles compatible volumes. ## This function returns shinyFiles compatible volumes.
...@@ -81,3 +85,9 @@ txt_file_input <- function(inputId,input,fileB,label,volumes) { ...@@ -81,3 +85,9 @@ txt_file_input <- function(inputId,input,fileB,label,volumes) {
} }
} }
rv_conf2conf <- function(rv) {
x <- shiny::reactiveValuesToList(rv$conf)
x$compounds<-shiny::reactiveValuesToList(rv$conf$compounds)
x
}
...@@ -67,8 +67,8 @@ mk_ui_config <- function() { ...@@ -67,8 +67,8 @@ mk_ui_config <- function() {
shinyFiles::shinySaveButton("saveConfB", shinyFiles::shinySaveButton("saveConfB",
"Save configuration.", "Save configuration.",
title="Save", title="Save",
filename = "conf-state.rds", filename = "conf-state.yaml",
"rds"), "yaml"),
shinyFiles::shinyFilesButton("restoreConfB", shinyFiles::shinyFilesButton("restoreConfB",
label="Restore configuration.", label="Restore configuration.",
multiple=F, multiple=F,
...@@ -135,7 +135,7 @@ react_conf_f <- function(input,output,session,rv,rf) { ...@@ -135,7 +135,7 @@ react_conf_f <- function(input,output,session,rv,rf) {
vls <- vols()() #Ugly! :) vls <- vols()() #Ugly! :)
vol <- path2vol(path) vol <- path2vol(path)
sel<-match(vol,vls) sel<-match(vol,vls)
validate(need(sel,"Yikes! Unable to detect current project's volume.")) validate(sel,msg="Yikes! Unable to detect current project's volume.")
res<-names(vls)[[sel]] res<-names(vls)[[sel]]
res res
}) })
...@@ -174,6 +174,14 @@ server_conf <- function(input,output,session,rv,rf) { ...@@ -174,6 +174,14 @@ server_conf <- function(input,output,session,rv,rf) {
defaultPath=dpath(),roots=vs) defaultPath=dpath(),roots=vs)
shinyFiles::shinyDirChoose(input, 'switchProjB',roots=vs) shinyFiles::shinyDirChoose(input, 'switchProjB',roots=vs)
obsrv_e(input$saveConfB, {
conf<-rv_conf2conf(rv)
vol <- vol_f()
fn <- shinyFiles::parseSavePath(roots=vol_f,input$saveConfB)[["datapath"]]
validate(fn,msg="Invalid file to save config to.")
write_conf(conf,fn)
})
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment