--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shiny-discuss/65c7dac1-9af4-4813-8a7f-1fc457908d0d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
library(topGO)
#Create an environment under module_env.
module_env$topGO <- new.env()
#Set the current environment
env <- module_env$topGO
#Create a variable to hold reactive variables just for the module
env$rval <- reactiveValues()
env$rval$status_text <- 'Idle.'
env$rval$table_preview <- NULL
#Make sure that you evaluate all of your items in the new environment.
#Use evalq()
evalq(envir=env, {
#UI object that will be rendered under ui_module
ui_topGO <-
tabsetPanel(
tabPanel('topGO Enrichment Analysis',
p('\n'),
actionButton('topGO.start', "Start module (create topGO data object)"),
actionButton('topGO.output', "Output data"),
actionButton('topGO.clear', "Clear data"),
HTML('<hr>'),
column(4,
h4('Analysis Settings'),
textInput('topGO.mapping',
value='org.Hs.eg.db',
label='Package/Database For Terms (Mapping)'
),
selectInput('topGO.select_ontology',
selected = 'BP',
label='Select Ontology',
choices = c('BP', 'MF', 'CC'),
multiple = FALSE
),
numericInput('topGO.pvalue_threshold',
label = 'P-value Threshold Of Interest',
value = 0.05,
min = 0,
max = 1,
step = 0.01
),
selectInput('topGO.algorithm',
label = 'Analysis Algorithm',
selected = 'fisher',
choices = c('fisher', 'ks', 't', 'globaltest', 'sum'),
multiple = FALSE
),
selectInput('topGO.statistic',
label = 'Analysis Statistic',
selected = 'classic',
choices = c('classic', 'elim', 'weight01', 'lea'),
multiple = FALSE
),
actionButton('topGO.start_analysis', 'Start analysis'),
HTML('<hr />'),
h4('Format Output Table'),
numericInput('topGO.numterms',
label = 'Number Of Terms',
value = 10,
min = 1,
step = 1
),
actionButton('topGO.generate_table', 'Generate term table')
),
column(8,
tabsetPanel(
tabPanel(title='Status',
verbatimTextOutput('topGO.status_text')
),
tabPanel(title='Preview Term Table',
tableOutput('topGO.term_table')
)
)
)
),
tabPanel('Help',
p('\n'),
shiny::includeMarkdown("modules/topGO/help.md")
)
)
#Create your variables here, so that you can specify them as
#input and output.
#Input
genes_and_pvalues <- NULL
#Output
terms_output <- NULL
#Variables
topGOdata <- NULL
test_results <- NULL
#Always remember to register your module at the end!
register_module(
name="Step [6] - Enrichment Analysis (topGO)",
module=ui_topGO,
envir=env,
inputs=c("genes_and_pvalues"),
outputs=c("terms_output")
)
})
moduleOptionUI <- function(id, title, ...) {
# Create the namespace.
ns <- shiny::NS(id)
# Get the elements; THESE MUST BE bsCollapsePanel
elements <- eval(substitute(...))
return(
bsCollapse(id=ns(id), multiple=TRUE, open='Hi',
bsCollapsePanel(title=title, value=title,
elements
)
)
)
}
moduleOptionServer <- function(input, output, session, envir=parent.env(environment()), expr) {
# Create a shorthand for the module environment.
e <- envir
# Preserve the executed expression.
expr <- base::substitute(expr)
# Execute the expression in a reactive context, but also encapsulated within the passed environment.
shiny::observe({
base::eval(expr, envir = e)
})
}
ui <- navbarPage(title='test',
fluidRow(
column(3,
p('asdfsadf')
),
column(9,
column(4,
moduleOptionUI(title = 'Module Options', id=ns('option1'),
p('What is up.')
),
moduleOptionUI(title = 'Option 1', id=ns('option2'),
p("Panel #2")
)
),
column(8,
p('preview part')
)
)
)
)
server <- function(input, output, session) {
}
env <- module_env$topGO
observeEvent(input$topGO.clear, {
env <- module_env$topGO
#Input
env$gene_and_pvalues <- NULL
#Output
env$terms_output <- NULL
#Variables
env$rval$status_text <- "Cleared data."
env$topGOdata <- NULL
gc()
})
#Use observeEvent to trigger on the change of a reactive value
#or input
observeEvent(input$topGO.start, {
#Unfortunately, we need to reset the environment
#for every trigger we use.
env <- module_env$topGO
env$ready = FALSE
withProgress(message='Loading gene/terms package/library...', {
tryCatch({
library(input$topGO.mapping, character.only = T)
env$ready = TRUE
}, warning = function(w) {
suppressWarnings(input$topGO.mapping, character.only = T)
env$ready = TRUE
print(w)
env$rval$status_text <- capture.output(print(w))
}, error = function(e) {
env$ready = FALSE
print(e)
env$rval$status_text <- capture.output(print(e))
})
})
#Operates on values under a pvalue threshold
if(env$ready) {
shinyjs::js$playSound('core_sound_tick')
withProgress(message='Creating topGO data object...', {
# env$genelist <- env$genes_and_pvalues
# env$temp_genelist <- env$genes_and_pvalues
# env$interested_genes <- as.integer(env$genelist %in% env$genes)
# names(env$interested_genes) <- env$genes_and_pvalues
tryCatch({
env$topGOdata <- invisible(
new("topGOdata",
ontology = "BP",
allGenes = p.adjust(env$genes_and_pvalues, method='BH'),
geneSel = function(x) {return(x < input$topGO.pvalue_threshold)},
nodeSize = 5,
annot = annFUN.org,
mapping = input$topGO.mapping,
ID = 'symbol'
)
)
env$rval$status_text <- capture.output(print(env$topGOdata))
shinyjs::js$playSound('core_sound_alert')
}, warning = function(w) {
env$topGOdata <- suppressWarnings(
invisible(
new("topGOdata",
ontology = input$topGO.select_ontology,
allGenes = p.adjust(env$genes_and_pvalues, method='BH'),
geneSel = function(x) {return(x < input$topGO.pvalue_threshold)},
nodeSize = 5,
annot = annFUN.org,
mapping = input$topGO.mapping,
ID = 'symbol'
)
)
)
#Capture a short description after the data is read.
env$rval$status_text <- capture.output(print(env$topGOdata))
env$rval$status_text <- paste(env$rval$status_text, w)
shinyjs::js$playSound('core_sound_alert')
}, error = function(e) {
print(e)
env$rval$status_text <- e
})
})
}
})
observeEvent(input$topGO.output, {
#Unfortunately, we need to reset the environment
#for every trigger we use.
env <- module_env$topGO
withProgress(message='Outputing term table...', {
env$terms_output <- env$rval$table_preview
})
#Use module_output() to output your modules
#disallow "Alice" from being output to the core
module_output(disallow=is.null)
})
observeEvent(input$topGO.start_analysis, {
env <- module_env$topGO
if (!is.null(env$topGOdata)) {
shinyjs::js$playSound('core_sound_tick')
withProgress(message='Running analysis...', {
env$rval$status_text <- capture.output(
env$test_results <- runTest(
object = env$topGOdata,
algorithm = input$topGO.statistic,
statistic = input$topGO.algorithm
)
)
})
shinyjs::js$playSound('core_sound_alert')
}
})
observeEvent(input$topGO.generate_table, {
env <- module_env$topGO
if (!is.null(env$test_results)) {
shinyjs::js$playSound('core_sound_tick')
withProgress(message='Generating table...', {
env$rval$table_preview <- GenTable(
env$topGOdata,
analysisScore = env$test_results,
numChar=999,
topNodes = input$topGO.numterms
)
})
}
})
#status text
output$topGO.status_text <- renderPrint({
env <- module_env$topGO
print(env$rval$status_text)
})
output$topGO.term_table <- renderTable({
env <- module_env$topGO
return(env$rval$table_preview)
})
--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shiny-discuss/54eab796-532d-49b0-870f-d39d93ea7752%40googlegroups.com.
library(shinyBS)
library(shiny)
moduleOptionUI <- function(id, title, ...) {
# Create the namespace.
ns <- shiny::NS(id)
# Get the elements; THESE MUST BE bsCollapsePanel
elements <- eval(substitute(...))
return(
bsCollapse(id=ns(id), multiple=TRUE, open='Hi',
bsCollapsePanel(title=title, value=title,
elements
)
)
)
}
moduleOption <- function(input, output, session, envir=parent.env(environment()), expr) {
# Create a shorthand for the module environment.
e <- envir
# Preserve the executed expression.
expr <- base::substitute(expr)
# Execute the expression in a reactive context.
shiny::observe({
base::eval(expr, envir = e)
})
}
ui <- navbarPage(title='Example',
tabPanel('Workflow',
fluidRow(
column(4,
actionButton('button', 'Stop'),
uiOutput('ui_core')
),
column(8,
uiOutput('ui_module')
)
)
)
)
core_env <- new.env()
core_env$rval <- reactiveValues()
core_env$rval$module_choices <- c('A', 'B', 'C')
core_env$rval$module_tags_category <- c('a', 'b', 'c')
core_env$rval$module_tags_workflow <- c('1', '2', '3')
core_env$rval$module_tags_function <- c('z', 'x', 'y')
core_env$rval$status_text <- 'Idle.'
coreStatusText <- function(string, core_env, session, style='warning') {
core_env$rval$status_text <- string
updateCollapse(session=session, id='Status', open='Status', style=list('Status'=style))
}
moduleCoreUI <- function(id, title, core_env, ...) {
# Create the namespace.
ns <- shiny::NS(id)
# Get the elements; THESE MUST BE bsCollapsePanel
elements <- eval(substitute(...))
div(
bsCollapse(
bsCollapsePanel(title='Status', value='status_open', style='info',
p('\n'),
p(core_env$rval$status_text)
)
),
wellPanel(
elements
)
)
}
moduleCoreServer <- function(input, output, session, core_env, expr) {
ns <- session$ns
# Create a shorthand for the module environment.
e <- core_env
# Preserve the executed expression.
eval(expr)
}
moduleContentsUI <- function(id, title, core_env, ...) {
# Create the namespace.
ns <- shiny::NS(id)
# Get the elements; THESE MUST BE bsCollapsePanel
elements <- eval(substitute(...))
div(
fluidRow(
column(6,
selectInput(ns('module_select'),
label='Select module',
multiple = FALSE,
choices = core_env$rval$module_choices,
selectize = TRUE)
),
column(2,
selectInput(ns('module_select_category'),
label='Category',
multiple = FALSE,
choices = core_env$rval$module_tags_category,
selectize = TRUE)
),
column(2,
selectInput(ns('module_search_workflow'),
label='Workflow',
multiple = FALSE,
choices = core_env$rval$module_tags_workflow,
selectize = TRUE)
),
column(2,
selectInput(ns('module_select_function'),
label='Function',
multiple = FALSE,
choices = core_env$rval$module_tags_function,
selectize = TRUE)
)
),
fluidRow(
column(4,
h4('Options')
#optionElements
),
column(8,
h4('Preview')
#previewElements
)
)
)
}
server <- function(input, output, session) {
output$ui_core <- renderUI({
ns <- session$ns
moduleCoreUI('g_core', 'Core', core_env,
actionButton(ns('button'), 'Change message')
)
})
output$ui_module <- renderUI({
ns <- session$ns
moduleContentsUI('g_module', 'Module', core_env)
})
observeEvent(input$button, {
browser()
updateCollapse(session=session, id='Status', open='Status', style=list('Status'='warning'))
})
callModule(moduleCoreServer, 'g_core', core_env=core_env, session=session, expr=
observeEvent(input$button, quote({
coreStatusText('Help!', core_env, session, 'warning')
print('asdf')
}))
)
}
shinyApp(ui, server)
--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shiny-discuss/d875ce7b-7a5b-477c-ac7d-2488a7363afe%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shiny-discuss/d6852328-3799-49a6-b6a0-a54218b453d1%40googlegroups.com.