Skip to content

Commit

Permalink
home module update
Browse files Browse the repository at this point in the history
- updating home module to display html reports generated outside of shiny that summarise the results
  • Loading branch information
jreps committed Nov 22, 2024
1 parent b0684a4 commit 129427c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 41 deletions.
63 changes: 25 additions & 38 deletions R/home-main.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ homeHelperFile <- function(){
return(fileLoc)
}

#' The module viewer for exploring home
#' The module viewer for exploring summary results
#'
#' @details
#' The user specifies the id for the module
Expand All @@ -26,47 +26,19 @@ homeHelperFile <- function(){
homeViewer <- function(id=1) {
ns <- shiny::NS(id)

screens <- list(
shinyglide::screen(
shiny::p("Assure Executive Summary"),
shiny::p("Study Name"),
shiny::p("The study question was..."),
shiny::p("<list available results>"),
next_label="Estimation Results"
),
shinyglide::screen(
shiny::p("Estimation Results"),
shiny::p("User Inputs are possible"),
shiny::numericInput(
inputId = ns("n"),
label = "n",
value = 10,
min = 10
),
next_label="Prediction Results"
),
shinyglide::screen(
shiny::p("Cool plot here"),
shiny::plotOutput(ns("cool_plot"))
)
)

shinydashboard::box(
status = 'info', width = 12,
title = shiny::span( shiny::icon("house"), "Executive Summary"),
title = shiny::span( shiny::icon("house"), "Summary Reports"),
solidHeader = TRUE,

shinyglide::glide(
height = "350px",
screens
)

# tabs per html file
shiny::uiOutput(ns("tabs"))
)

}


#' The module server for exploring home
#' The module server for exploring summary html files
#'
#' @details
#' The user specifies the id for the module
Expand All @@ -88,14 +60,29 @@ homeServer <- function(
id,
function(input, output, session) {

output$cool_plot <- shiny::renderPlot({
graphics::hist(
stats::rnorm(input$n),
main = paste("n =", input$n),
xlab = ""
# ShinyAppBuilder moves the html reports to the summaryReports folder
# and renames them to the tabname.html
# here we find all of these files as they end in html
htmlFiles <- dir(Sys.getenv('shiny_report_folder'), pattern = '.html')

# for each summary report in the summaryReports folder create a tab
# containing the html

output$tabs <- shiny::renderUI({
tabs <- list(NULL)
for(i in 1:length(htmlFiles)){
tabs[[i]] <- shiny::tabPanel(
title = gsub('.html','', htmlFiles[i]),
shiny::tags$iframe(
src = file.path('www-reports',htmlFiles[1]),
style='width:90vw;height:100vh;'
)
)
}
do.call(shinydashboard::tabBox,tabs)
})


}
)
}
14 changes: 11 additions & 3 deletions tests/testthat/test-home.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,16 @@ shiny::testServer(
),
expr = {

# check setting and generating works
session$setInputs(n = 30)
testthat::expect_true(input$n == 30)
# create a html file in a folder
# add the folder location to environmental var shiny_report_folder
tempDir <- file.path(tempdir(),'reports')
if(!dir.exists(tempDir)){
dir.create(tempDir, recursive = T)
}
write.table(x = c(a=1, b=2), file = file.path(tempDir, 'Prediction.html'))
Sys.setenv(shiny_report_folder = tempDir)
shiny::addResourcePath('www-reports', tempDir)

testthat::expect_true(!is.null(output$tabs))
})

0 comments on commit 129427c

Please sign in to comment.