Skip to content

Commit

Permalink
problem with eventReactive
Browse files Browse the repository at this point in the history
fawaz-dabbaghieh committed Nov 9, 2017
1 parent f8957f4 commit 2332f59
Showing 3 changed files with 53 additions and 48 deletions.
81 changes: 38 additions & 43 deletions app/server.r
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

function(input, output) {

#keeping track of he inserted UIs
@@ -7,32 +6,30 @@ function(input, output) {
#Adding the UI after choosing the UserID and clicking on the button
observeEvent(input$start_btn, {
id <- input$start_btn
#id <- btn


user <- deepblue_echo(user_key = input$user_key)
#if user gave a wrong user name he's be greeted as a stranger
#if user gave a wrong user name he'll be greeted as a stranger
if (tail(strsplit(user, split = " ")[[1]], n=1) == "Stranger" |
tail(strsplit(user, split = " ")[[1]], n=1) == "anonymous"){
user <- "anonymous_key"
showNotification(user, type = "message", duration = NULL)
showNotification(deepblue_echo(user_key=input$user_key), type = "message", duration = 10)
}

#he will be greated with his name
#else, the user will be greeted with his name
else{
user <- input$user_key
showNotification(deepblue_echo(user_key = input$user_key), type = "message", duration = NULL)
showNotification(deepblue_echo(user_key = input$user_key), type = "message", duration = 10)
}


#progress bar for loading the UI
withProgress(message = "Getting Projects, Epigenetics Marks, Chromosomes and Tests",min = 0,
max = 2, value = 0,
{

incProgress(amount = 1, message = "building stuff")
incProgress(amount = 1, message = "building input interface")

insertUI(selector = '#addOptions',
where = "afterBegin",
#We wrap the element in a div with id to remove it if the btn pressed again
#We wrap the element in a div with id to remove it when the restart buttong pressed
ui = tags$div(

id = id,
@@ -41,10 +38,14 @@ function(input, output) {
selected = "NULL"),

selectInput('project', 'Select Project', c(deepblue_list_projects(user_key = user)$name,
"NULL")),
"NULL"), selected = "NULL"),

selectInput('epigenetic_mark', 'Select an Epigenetic Mark',
c(deepblue_list_epigenetic_marks(user_key = user)$name, "NULL"), multiple = TRUE),
c(deepblue_list_epigenetic_marks(user_key = user)$name, "NULL"), multiple = TRUE,
selected = "NULL"),

actionButton('list_exper_btn', "List Experiments"),


radioButtons("type_of_score", "Choose method to calculate scoring matrix",choices=
c("Annotations" = "annotation", "Tiling Regions" = "tiling")),
@@ -53,39 +54,36 @@ function(input, output) {
conditionalPanel(
condition = "input.type_of_score == 'tiling'",
radioButtons("tiling_size", "Select Tiling Region Size", choices =
c("1000 base pairs" = "1000", "5000 base pairs" = "5000"))
)
c("1000 base pairs" = "1000", "5000 base pairs" = "5000")))

)
)
inserted <<- c(id, inserted)
incProgress(amount = 1, message = "done")

})
})

#Adding a small UI for choosing the chromosome according the genome chosen
observeEvent(input$genome, {

if(input$genome != "NULL"){
# chromsome <- input$genome
genomes <- deepblue_list_genomes(user_key = input$user_key)

insertUI(selector = '#addChromosomes',
where = "afterEnd",
ui = tags$div(
print(genomes),
selectInput('chr', 'Select a Chromosome, or NULL for all genome',
c(deepblue_info(id = genomes$id[grep(input$genome, genomes$name)],
user_key = input$user_key)$chromosomes$name, "NULL"),
multiple = TRUE),
id = "fawaz"

id = "add_chr"
)
)
}

})



#To remove the inserted UI and start again
observeEvent(input$end_btn, {
removeUI(
@@ -94,52 +92,49 @@ function(input, output) {
)
inserted <<- inserted[-length(inserted)]
removeUI(
selector = '#fawaz', multiple = TRUE
selector = '#add_chr', multiple = TRUE
)
})


#Removing the inserted Chromosome choices
# observeEvent(input$end_btn, {
# removeUI(
# selector = "div:has(> #chr)", multiple = TRUE
# )
# })

all_experiments <- eventReactive(input$button, {

#List experiments and info for experiments in a list
all_experiments <- eventReactive(input$list_exper_btn, {
#getting experments
list_experiments(genome = input$genome, epigenetic_mark = input$epigenetic_mark, project = input$project,
browser()
all_experiments <- list_experiments(genome = input$genome, epigenetic_mark = input$epigenetic_mark, project = input$project,
user_key = input$user_key)

})

# experiments_info <- eventReactive(input$button, {
# #getting info
# deepblue_info(id = all_experiments()[[1]]$id, user_key = input$user_key)
# })

experiments_info_meta <- eventReactive(input$button, {
eventReactive(input$list_exper_btn, {
output$table <- renderTable(all_experiments())

})

#make a table of metadata
experiments_info_meta <- eventReactive(input$plot_btn, {
browser()
#extract metadata
experiments_info_meta <- extract_metadata(all_experiments()[[2]])

})

filtered_score_matrix <- eventReactive(input$button, {
#Get the score matrix
filtered_score_matrix <- eventReactive(input$plot_btn, {
#get scoring matrix
score_matrix_tiling_regions(experiments = all_experiments()[[1]], experiments_info_meta = experiments_info_meta(),
genome = input$genome, chr = input$chr, user_key = input$user_key)
})


plot_pca <- eventReactive(input$button, {
#plot data
plot_pca <- eventReactive(input$plot_btn, {
#get plot
plot_pca_labels(experiments_info_meta = experiments_info_meta(),
project = input$project,
filtered_score_matrix = filtered_score_matrix(),
epigenetic_mark = input$epigenetic_mark)
})

output$plot1 <- renderPlotly(plot_pca())
output$plot <- renderPlotly(plot_pca())

}
10 changes: 8 additions & 2 deletions app/ui.r
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@ source("/home/fawaz/Desktop/Max_Planck_Job/shiny_apps/shinyApp/functions/score_m
source("/home/fawaz/Desktop/Max_Planck_Job/shiny_apps/shinyApp/functions/plot_pca_labels.r")
source("/home/fawaz/Desktop/Max_Planck_Job/shiny_apps/shinyApp/functions/plot_correlation.r")

#JvkPLwsTHbb3Fyi4

fluidPage(

@@ -31,11 +32,16 @@ fluidPage(
tags$div(id = 'addOptions'),
tags$div(id = 'addChromosomes'),

actionButton("button", "Caclulate and Plot")
actionButton("plot_btn", "Caclulate and Plot")

),

mainPanel(
plotlyOutput('plot1', width = "100%", height = "600px")
tabsetPanel(type = "tabs",
tabPanel("Table", tableOutput("table")),
tabPanel("Summary", tableOutput("summary")),
tabPanel("Plot", plotlyOutput('plot', width = "100%", height = "600px"))

)
)
)
10 changes: 7 additions & 3 deletions functions/list_experiments.r
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ list_experiments <- function(genome, epigenetic_mark, project, user_key){

#The DeepBlue accepts a NULL epigenetics mark, but shiny app returns NULL as a string so I added
#this small rule
if(epigenetic_mark == "NULL"){ epigenetic_mark = NULL}
if(epigenetic_mark == "NULL"){epigenetic_mark = NULL}

#Same for Genome
if(genome == "NULL"){genome = NULL}
@@ -19,15 +19,17 @@ list_experiments <- function(genome, epigenetic_mark, project, user_key){
epigenetic_mark = epigenetic_mark,
project = project,
user_key = user_key)

print("got experiments")
#In case no experiments returned, the function will just return an empty line and will be reported
#to the user
if (experiments == "\n"){
if (experiments[1] == "\n"){
return("\n")
}

#Getting experiments info
print("going to get info")
experiments_info <- deepblue_info(id = experiments$id, user_key = user_key)
print("done getting info")

#From the list of experiments, I only need to keep the ones with the VALUE column
format <- "CHROMOSOME,START,END,VALUE"
@@ -53,5 +55,7 @@ list_experiments <- function(genome, epigenetic_mark, project, user_key){
#Return a list with two elements, First is the lsit of experiments
#the second is all the information in a list
all_experiments <- list(experiments, experiments_info)
print("returning experiments list")
print(summary(all_experiments))
return(all_experiments)
}

0 comments on commit 2332f59

Please sign in to comment.