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

Introduce modular reactive values/functions concept

Because we decided to split the server and UI definitions into
separate "modules", we also needed to create a way for different
modules to exchange their reactive values and functions.

In this regard, each module is going to have two server-like
functions, react_module-name_f and react_module-name_v, which will
define and return reactive functions and objects, respectively. Each
such function is server-like, i.e. it will take input, output and
session arguments. The two remaining arguments are rv and rf, for the
input reactive values and functions.

* R/shiny-ui-config.R(react_conf_v): New function.
  Add conf-related reactive values.

  (react_vonf_f): New function. Add conf-related reactive functions.

  (server_conf): Update observers.

* R/shiny-ui-top.R(server): Adapt to the new concept.
parent 7bb9ece5
No related branches found
No related tags found
No related merge requests found
......@@ -118,5 +118,62 @@ mk_ui_config <- function() {
side=confSideItem))
}
react_conf_v <- function(input,output,session,rv,rf) {
rv$conf <- react_v(data=CONF$data,
project=CONF$project,
compounds=react_v(known=CONF$compounds$known,
unknown=CONF$compounds$unknown,
sets=CONF$compounds$sets))
rv
}
react_conf_f <- function(input,output,session,rv,rf) {
rf$get_proj_vol <- react_e(rv$conf$project,{
## For shinyfiles dialogs.
path <- normalizePath(rv$conf$project, winslash = '/')
vls <- vols()() #Ugly! :)
vol <- path2vol(path)
sel<-match(vol,vls)
validate(need(sel,"Yikes! Unable to detect current project's volume."))
res<-names(vls)[[sel]]
res
})
rf$get_proj_path <- react_e(rv$conf$project,{
## For shinyfiles dialogs.
wd <- rv$conf$project
vol <- rf$get_proj_vol()
v <- vols()()
pref<-v[[vol]]
res<-wd
message('Relative project path is: ',res)
res
})
rf
}
server_conf <- function(input,output,session) {}
server_conf <- function(input,output,session,rv,rf) {
## ***** shinyFiles observers *****
droot <- rf$get_proj_vol
dpath <- rf$get_proj_path
vs <- vols()
shinyFiles::shinyFileChoose(input, 'impKnownListB',defaultRoot=droot(),
defaultPath=dpath(),roots=vs)
shinyFiles::shinyFileChoose(input, 'impUnkListB',defaultRoot=droot(),
defaultPath=dpath(),roots=vs)
shinyFiles::shinyFileChoose(input, 'impSetIdB',defaultRoot=droot(),
defaultPath=dpath(),roots=vs)
shinyFiles::shinyFileSave(input, 'saveConfB',defaultRoot=droot(),
defaultPath=dpath(),roots=vs)
shinyFiles::shinyFileChoose(input, 'restoreConfB',defaultRoot=droot(),
defaultPath=dpath(),roots=vs)
shinyFiles::shinyFileChoose(input, 'mzMLB',defaultRoot=droot(),
defaultPath=dpath(),roots=vs)
shinyFiles::shinyDirChoose(input, 'switchProjB',roots=vs)
}
......@@ -46,7 +46,17 @@ mk_ui <- function (fn_style) {
mk_shinyscreen <- function(fn_style=system.file('www/custom.css',package = 'shinyscreen')) {
server <- function(input,output,session) {
## Top-level server function.
server_conf(input,output,session)
rv <- shiny::reactiveValues(dummy=1) # Container for all
# reactive values.
rf <- list() # Container for all
# reactive functions.
rv <- react_conf_v(input,output,session,rv=rv,rf=rf) # Config related r. values.
rf <- react_conf_f(input,output,session,rv=rv,rf=rf) # Config related r. functions.
## Observers and renderers.
server_conf(input,output,session,rv=rv,rf=rf)
session$onSessionEnded(function () {
stopApp()
})
......
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