Skip to content

Commit

Permalink
i think the current working version
Browse files Browse the repository at this point in the history
  • Loading branch information
cmatKhan committed Apr 23, 2024
1 parent 9ff8207 commit c322eaa
Show file tree
Hide file tree
Showing 8 changed files with 138 additions and 100 deletions.
2 changes: 1 addition & 1 deletion R/data.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#' Base url of the database API
#'
#' @export
base_url <- "http://ec2-13-59-35-163.us-east-2.compute.amazonaws.com"
base_url <- "http://ec2-3-143-144-93.us-east-2.compute.amazonaws.com"

#' Rank Response Plot Example
#'
Expand Down
168 changes: 98 additions & 70 deletions R/qcTableModule.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,84 +74,112 @@ qcTableServer <- function(id, tf_id, token) {
}
}

# instantiate reactives
rv <- shiny::reactiveValues(data = NULL, trigger=FALSE)
tf_manual_review_changes <- reactiveValues(data = NULL)

proxy <- DT::dataTableProxy("tf_manual_review_table")

# Initialize the reactiveValues object with your data frame
rv <- shiny::reactiveValues(data = labretriever::retrieve(
labretriever::create_url("qcreview",
base_url = yeastCCDBShiny::base_url
),
token(),
filter_list = list(tf_id = tf_id())
) %>%
dplyr::arrange(experiment_id))

tf_manual_review_changes = reactiveValues(data = NULL)

output$tf_manual_review_table <- DT::renderDataTable({
DT::datatable(
rv$data,
editable = TRUE,
selection = "single",
options = list(
scrollX = TRUE,
width = "100%"
shiny::observe({
shiny::req(token(), tf_id())
qc_df <- labretriever::retrieve(
labretriever::create_url("qcreview",
base_url = yeastCCDBShiny::base_url
),
token(),
filter_list = list(tf_id = tf_id())
) %>%
dplyr::arrange(experiment_id)
rv$data <- qc_df

output$tf_manual_review_table <- DT::renderDataTable({
DT::datatable(
rv$data,
editable = TRUE,
selection = "single",
options = list(
scrollX = TRUE,
width = "100%"
)
)
)
}) # Set server to FALSE to make proxy work
}) # Set server to FALSE to make proxy work
})

observeEvent(input$update_button,
{
shiny::req(tf_id())
# Check if there are any changes
if (length(tf_manual_review_changes$data) > 0) {
# Process the changes and send updates to the database
tryCatch({
# Iterate through the changes and send updates for each changed field
for (change in tf_manual_review_changes$data) {
labretriever::send(
df = change,
url = labretriever::create_url(
"qcreview",
base_url = yeastCCDBShiny::base_url
),
token = token(),
update = TRUE
)
}
# Update the showButtons reactive value
shiny::updateCheckboxInput(session, "showButtons", value = FALSE)
}, error = function(err) {
# If an error occurs, show a modal with the error message
showModal(modalDialog(
title = "Error",
paste0(
"An error occurred while updating the data: ",
err$message, "\n\n",
"ALL CHANGES CLEARED"
),
easyClose = TRUE
))
}, finally = {
# retrieve the updated data and update the reactive
updated_data <- labretriever::retrieve(
labretriever::create_url("qcreview",
base_url = yeastCCDBShiny::base_url
),
token(),
filter_list = list(tf_id = tf_id())
)
# update the review reactive
rv$data <- updated_data

# Clear the changes list
tf_manual_review_changes$data <- list()
})
}
},
ignoreInit = TRUE
{
shiny::req(tf_id())
# Check if there are any changes
if (length(tf_manual_review_changes$data) > 0) {
# Process the changes and send updates to the database
tryCatch({
# Iterate through the changes and send updates for each changed field
for (change in tf_manual_review_changes$data) {
res = labretriever::send(
df = change,
url = labretriever::create_url(
"qcreview",
base_url = yeastCCDBShiny::base_url
),
token = token(),
update = TRUE
)
}
# Update the showButtons reactive value
shiny::updateCheckboxInput(session, "showButtons", value = FALSE)
}, error = function(err) {
# If an error occurs, show a modal with the error message
showModal(modalDialog(
title = "Error",
paste0(
"An error occurred while updating the data: ",
err$message, "\n\n",
"ALL CHANGES CLEARED"
),
easyClose = TRUE
))
}, finally = {
# retrieve the updated data and update the reactive
updated_data <- labretriever::retrieve(
labretriever::create_url("qcreview",
base_url = yeastCCDBShiny::base_url
),
token(),
filter_list = list(tf_id = tf_id())
)
# update the review reactive
rv$data <- updated_data

# Clear the changes list
tf_manual_review_changes$data <- list()
})
}
},
ignoreInit = TRUE
)

shiny::observeEvent(input$cancel_update_button, {
# Update the showButtons reactive value
shiny::updateCheckboxInput(session, "showButtons", value = FALSE)
# Clear the changes list
tf_manual_review_changes$data <- list()
rv$trigger <- !rv$trigger
}, ignoreInit = TRUE)

shiny::observeEvent(rv$trigger, {
output$tf_manual_review_table <- DT::renderDataTable({
DT::datatable(
rv$data,
editable = TRUE,
selection = "single",
options = list(
scrollX = TRUE,
width = "100%"
)
)
}) # Set server to FALSE to make proxy work
})

shiny::observeEvent(input$tf_manual_review_table_cell_edit, {
# Code to handle the table cell edit event
# Update the showButtons reactive value
Expand Down
12 changes: 10 additions & 2 deletions R/rankResponsePlotModule.R
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ rankResponsePlotServer <- function(id,
rr_df <- reactiveVal(NULL)

shiny::observeEvent(tf_id(), {

shiny::req(tf_id())

if (test) {
if (tf_gene() == "HAP5") {
rr_df(yeastCCDBShiny::hap5_rr_data)
Expand All @@ -135,6 +138,7 @@ rankResponsePlotServer <- function(id,

shiny::observeEvent(hops_source(),
{
shiny::req(tf_id())
if (test) {
if (tf_gene() == "HAP5") {
rr_df(yeastCCDBShiny::hap5_rr_data)
Expand All @@ -156,6 +160,7 @@ rankResponsePlotServer <- function(id,

shiny::observeEvent(background_source(),
{
shiny::req(tf_id())
if (test) {
if (tf_gene() == "HAP5") {
rr_df(yeastCCDBShiny::hap5_rr_data)
Expand All @@ -177,6 +182,7 @@ rankResponsePlotServer <- function(id,

shiny::observeEvent(promoter_source(),
{
shiny::req(tf_id())
if (test) {
if (tf_gene() == "HAP5") {
rr_df(yeastCCDBShiny::hap5_rr_data)
Expand All @@ -201,7 +207,8 @@ rankResponsePlotServer <- function(id,
rr_df(),
tf_gene(),
normalize_selector(),
bin_size()
bin_size(),
confidence_intervals()
)
flog.info(paste0('names of gen_plot_data_out: ',
paste(names(gen_plot_data_out), collapse = '", "')))
Expand Down Expand Up @@ -254,7 +261,8 @@ rankResponsePlotServer <- function(id,
rr_df(),
tf_gene(),
normalize_selector(),
bin_size()
bin_size(),
confidence_intervals()
)
rr_plots$kemmeren_tfko <- gen_plot_data_out$plt$kemmeren_tfko
rr_plots$mcisaac_zev <- gen_plot_data_out$plt$mcisaac_zev
Expand Down
3 changes: 1 addition & 2 deletions R/rank_response_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,7 @@ stable_rank_response <- function(df,
dplyr::mutate(
test_result = list(binom.test(n_successes,
rank,
p = random,
alternative = "greater"
p = random
)),
response_ratio = test_result$estimate,
p_value = test_result$p.value,
Expand Down
2 changes: 2 additions & 0 deletions R/retrieve_rank_response_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ retrieve_rank_response_data <- function(tf_gene,
background_source,
promoter_source,
token) {

rank_response_df = NA
N_STEPS <- 5
result <- shiny::withProgress(
message = "Fetching data...",
Expand Down
3 changes: 3 additions & 0 deletions R/tfSelectorModule.R
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ tfSelectorServer <- function(id,

# retrieve list of active TFs
shiny::observe({

shiny::req(token())

tf_list_df <- labretriever::retrieve(
labretriever::create_url("cctf_tf_list",
base_url = yeastCCDBShiny::base_url
Expand Down
Binary file removed data/rank_response_df.rda
Binary file not shown.
48 changes: 23 additions & 25 deletions inst/app/server.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,33 +46,31 @@ server <- function(input, output, session) {
)
})

shiny::observeEvent(rank_threshold(), {
goServer('go_module', rank_response_df, rank_threshold)
}, ignoreNULL = TRUE)

shiny::observeEvent(selected_tf_tracker(),
shiny::observeEvent(rank_threshold(),
{
rankResponsePlotServer(
"rr_plot",
shiny::reactive(selected_tf$tf_id),
shiny::reactive(selected_tf$tf_gene),
rank_response_df,
selected_row,
hops_source,
background_source,
promoter_source,
bin_size,
normalize_selector,
confidence_intervals,
token
)
qcTableServer(
"qc_table",
shiny::reactive(selected_tf$tf_id),
token
)
goServer("go_module", rank_response_df, rank_threshold)
},
ignoreInit = TRUE,
ignoreNULL = TRUE
)

rankResponsePlotServer(
"rr_plot",
shiny::reactive(selected_tf$tf_id),
shiny::reactive(selected_tf$tf_gene),
rank_response_df,
selected_row,
hops_source,
background_source,
promoter_source,
bin_size,
normalize_selector,
confidence_intervals,
token
)

qcTableServer(
"qc_table",
shiny::reactive(selected_tf$tf_id),
token
)
}

0 comments on commit c322eaa

Please sign in to comment.