Skip to content

Commit

Permalink
Add pdf view
Browse files Browse the repository at this point in the history
  • Loading branch information
loye16 committed Sep 11, 2023
1 parent e882d9f commit df26000
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
5 changes: 4 additions & 1 deletion UIs/ui_plot_single_result.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ plot_decoding <- tabPanel(
"Type of results to plot",
cm_result_type),
withSpinner(plotOutput("plot_cm"),
color = "#79c9da"))
color = "#79c9da")),
tabPanel("Show PDF",
uiOutput("show_single_result_pdf"))

)
)
)
1 change: 1 addition & 0 deletions global.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ library('plotly')
library('shinycssloaders')
library('shinyFiles')
library('DT')
library('pdftools')
library('tools')
rm(list=ls())

Expand Down
52 changes: 52 additions & 0 deletions servers/server_plot_single_result.R
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,55 @@ output$plot_cm <- renderPlot({
plot(rv$result_data$rm_confusion_matrix,
results_to_show = input$plot_cm_result_type)
})


################################################################################
################################## PDF Output ##################################
################################################################################

# Create list of valid PDFs from the results
observeEvent(list(rv$working_dir, input$plot_chosen_result, input$DC_run_script), {
req(rv$working_dir, input$plot_chosen_result)

# Resetting this value, only changed if a pdf is found later
rv$found_single_result_pdf <- FALSE

# Getting the analysis ID
analysis_id <- sub("\\.[Rr]da$", "", input$plot_chosen_result)

# Find the directories that end in PDF
result_dir <- list.dirs(rv$decoding_results_base_dir,
full.names = FALSE, recursive = FALSE)
pdf_dirs <- result_dir[grep("_pdf$", result_dir)]
pdf_list <- c()

# Find all the pdfs in pdf directories
for(directory in pdf_dirs) {
pdfs <- list.files(file.path(rv$decoding_results_base_dir, directory),
pattern = ".pdf$")
for (p in pdfs){
curr_pdf <- file.path(rv$decoding_results_base_dir, directory, p)
text <- pdf_text(curr_pdf)

if(any(grepl(paste("The analysis ID is:", analysis_id), text))){
dest_pdf <- file.path(app_base_dir, "www", "single_result_to_show.pdf")
file.copy(curr_pdf, dest_pdf)
rv$found_single_result_pdf <- TRUE
}
}
}
})



# Show the pdf
output$show_single_result_pdf <- renderUI({
validate(
need(input$plot_chosen_result, "No pdfs available")
)
validate(
need(rv$found_single_result_pdf, "No available pdf for this analysis id")
)
tags$iframe(style="height:600px; width:100%",
src = "single_result_to_show.pdf")
})

0 comments on commit df26000

Please sign in to comment.