From f07979e57c98a419fbd512afd508b890c97ee839 Mon Sep 17 00:00:00 2001 From: Andreas Gammelgaard Damsbo Date: Wed, 18 Dec 2024 11:26:00 +0100 Subject: [PATCH] re-added the report download option --- inst/apps/data_analysis_modules/app.R | 50 ++++++++++++++++--- .../shinyapps.io/agdamsbo/freesearcheR.dcf | 2 +- inst/apps/data_analysis_modules/server.R | 15 +++++- inst/apps/data_analysis_modules/ui.R | 35 +++++++++++-- .../apps/data_analysis_modules/www/report.qmd | 10 +++- 5 files changed, 97 insertions(+), 15 deletions(-) diff --git a/inst/apps/data_analysis_modules/app.R b/inst/apps/data_analysis_modules/app.R index a255e38..1d70643 100644 --- a/inst/apps/data_analysis_modules/app.R +++ b/inst/apps/data_analysis_modules/app.R @@ -2065,10 +2065,35 @@ ui_elements <- list( class = "fa-spin", "aria-hidden" = "true" ), - type = "primary", + type = "secondary", auto_reset = TRUE ), - shiny::helpText("If you change the parameters, press 'Analyse' again to update the tables") + shiny::helpText("If you change the parameters, press 'Analyse' again to update the tables"), + # shiny::conditionalPanel( + # condition = "output.ready=='yes'", + shiny::tags$hr(), + shiny::h4("Download results"), + shiny::helpText("Choose your favourite output file format for further work, and download, when the analyses are done."), + shiny::selectInput( + inputId = "output_type", + label = "Output format", + selected = NULL, + choices = list( + "Word" = "docx", + "LibreOffice" = "odt" + # , + # "PDF" = "pdf", + # "All the above" = "all" + ) + ), + shiny::br(), + # Button + shiny::downloadButton( + outputId = "report", + label = "Download", + icon = shiny::icon("download") + ) + # ) # ) ), bslib::nav_panel( @@ -2100,8 +2125,10 @@ ui_elements <- list( # Initial attempt at creating light and dark versions light <- custom_theme() -dark <- custom_theme(bg = "#000", - fg="#fff") +dark <- custom_theme( + bg = "#000", + fg = "#fff" +) # Fonts to consider: # https://webdesignerdepot.com/17-open-source-fonts-youll-actually-love/ @@ -2190,7 +2217,7 @@ server <- function(input, output, session) { ds = NULL, input = exists("webResearch_data"), local_temp = NULL, - quarto = NULL, + ready = NULL, test = "no", data_original = NULL, data = NULL, @@ -2562,6 +2589,8 @@ server <- function(input, output, session) { # patchwork::wrap_plots(ncol=1) + # patchwork::plot_annotation(title = 'Multivariable regression model checks') + + rv$ready <- "ready" }) } ) @@ -2588,6 +2617,15 @@ server <- function(input, output, session) { shiny::outputOptions(output, "uploaded", suspendWhenHidden = FALSE) + output$ready <- shiny::reactive({ + if (is.null(rv$ready)) { + "no" + } else { + "yes" + } + }) + + shiny::outputOptions(output, "ready", suspendWhenHidden = FALSE) # Reimplement from environment at later time # output$has_input <- shiny::reactive({ @@ -2610,7 +2648,7 @@ server <- function(input, output, session) { content = function(file, type = input$output_type) { ## Notification is not progressing ## Presumably due to missing - shiny::withProgress(message = "Generating report. Hold on for a moment..", { + shiny::withProgress(message = "Generating the report. Hold on for a moment..", { rv$list |> write_quarto( output_format = type, diff --git a/inst/apps/data_analysis_modules/rsconnect/shinyapps.io/agdamsbo/freesearcheR.dcf b/inst/apps/data_analysis_modules/rsconnect/shinyapps.io/agdamsbo/freesearcheR.dcf index 0939d8b..8d0b399 100644 --- a/inst/apps/data_analysis_modules/rsconnect/shinyapps.io/agdamsbo/freesearcheR.dcf +++ b/inst/apps/data_analysis_modules/rsconnect/shinyapps.io/agdamsbo/freesearcheR.dcf @@ -5,6 +5,6 @@ account: agdamsbo server: shinyapps.io hostUrl: https://api.shinyapps.io/v1 appId: 13611288 -bundleId: 9533633 +bundleId: url: https://agdamsbo.shinyapps.io/freesearcheR/ version: 1 diff --git a/inst/apps/data_analysis_modules/server.R b/inst/apps/data_analysis_modules/server.R index 50fa546..27de410 100644 --- a/inst/apps/data_analysis_modules/server.R +++ b/inst/apps/data_analysis_modules/server.R @@ -64,7 +64,7 @@ server <- function(input, output, session) { ds = NULL, input = exists("webResearch_data"), local_temp = NULL, - quarto = NULL, + ready = NULL, test = "no", data_original = NULL, data = NULL, @@ -436,6 +436,8 @@ server <- function(input, output, session) { # patchwork::wrap_plots(ncol=1) + # patchwork::plot_annotation(title = 'Multivariable regression model checks') + + rv$ready <- "ready" }) } ) @@ -462,6 +464,15 @@ server <- function(input, output, session) { shiny::outputOptions(output, "uploaded", suspendWhenHidden = FALSE) + output$ready <- shiny::reactive({ + if (is.null(rv$ready)) { + "no" + } else { + "yes" + } + }) + + shiny::outputOptions(output, "ready", suspendWhenHidden = FALSE) # Reimplement from environment at later time # output$has_input <- shiny::reactive({ @@ -484,7 +495,7 @@ server <- function(input, output, session) { content = function(file, type = input$output_type) { ## Notification is not progressing ## Presumably due to missing - shiny::withProgress(message = "Generating report. Hold on for a moment..", { + shiny::withProgress(message = "Generating the report. Hold on for a moment..", { rv$list |> write_quarto( output_format = type, diff --git a/inst/apps/data_analysis_modules/ui.R b/inst/apps/data_analysis_modules/ui.R index 196b9e1..75e3d86 100644 --- a/inst/apps/data_analysis_modules/ui.R +++ b/inst/apps/data_analysis_modules/ui.R @@ -225,10 +225,35 @@ ui_elements <- list( class = "fa-spin", "aria-hidden" = "true" ), - type = "primary", + type = "secondary", auto_reset = TRUE ), - shiny::helpText("If you change the parameters, press 'Analyse' again to update the tables") + shiny::helpText("If you change the parameters, press 'Analyse' again to update the tables"), + # shiny::conditionalPanel( + # condition = "output.ready=='yes'", + shiny::tags$hr(), + shiny::h4("Download results"), + shiny::helpText("Choose your favourite output file format for further work, and download, when the analyses are done."), + shiny::selectInput( + inputId = "output_type", + label = "Output format", + selected = NULL, + choices = list( + "Word" = "docx", + "LibreOffice" = "odt" + # , + # "PDF" = "pdf", + # "All the above" = "all" + ) + ), + shiny::br(), + # Button + shiny::downloadButton( + outputId = "report", + label = "Download", + icon = shiny::icon("download") + ) + # ) # ) ), bslib::nav_panel( @@ -260,8 +285,10 @@ ui_elements <- list( # Initial attempt at creating light and dark versions light <- custom_theme() -dark <- custom_theme(bg = "#000", - fg="#fff") +dark <- custom_theme( + bg = "#000", + fg = "#fff" +) # Fonts to consider: # https://webdesignerdepot.com/17-open-source-fonts-youll-actually-love/ diff --git a/inst/apps/data_analysis_modules/www/report.qmd b/inst/apps/data_analysis_modules/www/report.qmd index 51e3faa..0a2aed2 100644 --- a/inst/apps/data_analysis_modules/www/report.qmd +++ b/inst/apps/data_analysis_modules/www/report.qmd @@ -16,6 +16,7 @@ params: web_data <- readr::read_rds(file = params$data.file) library(gtsummary) library(gt) +library(flextable) library(easystats) library(patchwork) # library(webResearch) @@ -36,7 +37,9 @@ Below is the baseline characteristics plotted. ```{r} #| label: tbl-baseline #| tbl-cap: Baseline characteristics of included data -web_data$table1 +web_data$table1 |> + gtsummary::as_flex_table() |> + flextable::set_table_properties(width = 1, layout = "autofit") ``` Here are the regression results. @@ -44,9 +47,12 @@ Here are the regression results. ```{r} #| label: tbl-regression #| tbl-cap: Regression analysis results -web_data$table2 +web_data$table2|> + gtsummary::as_flex_table() |> + flextable::set_table_properties(width = 1, layout = "autofit") ``` + ## Discussion Good luck on your further work!