2024-12-09 14:00:44 +01:00
|
|
|
# project.aid::merge_scripts(list.files("R/",full.names = TRUE),dest = here::here("app/functions.R"))
|
|
|
|
# source(here::here("app/functions.R"))
|
|
|
|
|
|
|
|
# source("https://raw.githubusercontent.com/agdamsbo/webResearch/refs/heads/main/app/functions.R")
|
|
|
|
|
|
|
|
library(readr)
|
|
|
|
library(MASS)
|
|
|
|
library(stats)
|
|
|
|
library(gtsummary)
|
|
|
|
library(gt)
|
|
|
|
library(openxlsx2)
|
|
|
|
library(haven)
|
|
|
|
library(readODS)
|
2024-12-17 11:44:01 +01:00
|
|
|
require(shiny)
|
2024-12-09 14:00:44 +01:00
|
|
|
library(bslib)
|
|
|
|
library(assertthat)
|
|
|
|
library(dplyr)
|
|
|
|
library(quarto)
|
|
|
|
library(here)
|
|
|
|
library(broom)
|
|
|
|
library(broom.helpers)
|
|
|
|
library(REDCapCAST)
|
|
|
|
library(easystats)
|
|
|
|
library(patchwork)
|
|
|
|
library(DHARMa)
|
2024-12-13 13:37:19 +01:00
|
|
|
library(datamods)
|
|
|
|
library(toastui)
|
|
|
|
library(IDEAFilter)
|
2024-12-17 11:44:01 +01:00
|
|
|
library(shinyWidgets)
|
|
|
|
library(DT)
|
2024-12-09 14:00:44 +01:00
|
|
|
# if (!requireNamespace("webResearch")) {
|
|
|
|
# devtools::install_github("agdamsbo/webResearch", quiet = TRUE, upgrade = "never")
|
|
|
|
# }
|
|
|
|
# library(webResearch)
|
|
|
|
|
2024-12-18 10:37:37 +01:00
|
|
|
# source("functions.R")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# light <- custom_theme()
|
|
|
|
#
|
|
|
|
# dark <- custom_theme(bg = "#000",
|
|
|
|
# fg="#fff")
|
|
|
|
|
|
|
|
|
2024-12-09 14:00:44 +01:00
|
|
|
|
|
|
|
server <- function(input, output, session) {
|
|
|
|
## Listing files in www in session start to keep when ending and removing
|
|
|
|
## everything else.
|
|
|
|
files.to.keep <- list.files("www/")
|
|
|
|
|
2024-12-18 10:37:37 +01:00
|
|
|
# observeEvent(input$dark_mode,{
|
|
|
|
# session$setCurrentTheme(
|
|
|
|
# if (isTRUE(input$dark_mode)) dark else light
|
|
|
|
# )})
|
|
|
|
|
2024-12-17 11:30:17 +01:00
|
|
|
output$docs_file <- renderUI({
|
|
|
|
# shiny::includeHTML("www/docs.html")
|
|
|
|
HTML(readLines("www/docs.html"))
|
|
|
|
})
|
|
|
|
|
2024-12-16 22:21:54 +01:00
|
|
|
rv <- shiny::reactiveValues(
|
2024-12-18 15:46:02 +01:00
|
|
|
list = list(),
|
2024-12-09 14:00:44 +01:00
|
|
|
ds = NULL,
|
|
|
|
input = exists("webResearch_data"),
|
|
|
|
local_temp = NULL,
|
2024-12-18 11:26:00 +01:00
|
|
|
ready = NULL,
|
2024-12-13 13:37:19 +01:00
|
|
|
test = "no",
|
2024-12-16 22:21:54 +01:00
|
|
|
data_original = NULL,
|
|
|
|
data = NULL,
|
|
|
|
data_filtered = NULL
|
2024-12-09 14:00:44 +01:00
|
|
|
)
|
|
|
|
|
2024-12-16 22:21:54 +01:00
|
|
|
##############################################################################
|
|
|
|
#########
|
|
|
|
######### Data import section
|
|
|
|
#########
|
|
|
|
##############################################################################
|
|
|
|
|
2024-12-09 14:00:44 +01:00
|
|
|
data_file <- datamods::import_file_server(
|
|
|
|
id = "file_import",
|
|
|
|
show_data_in = "popup",
|
2024-12-13 13:37:19 +01:00
|
|
|
trigger_return = "change",
|
2024-12-09 14:00:44 +01:00
|
|
|
return_class = "data.frame",
|
|
|
|
read_fns = list(
|
|
|
|
ods = function(file) {
|
|
|
|
readODS::read_ods(path = file)
|
|
|
|
},
|
|
|
|
dta = function(file) {
|
|
|
|
haven::read_dta(file = file)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2024-12-16 22:21:54 +01:00
|
|
|
shiny::observeEvent(data_file$data(), {
|
|
|
|
shiny::req(data_file$data())
|
|
|
|
rv$data_original <- data_file$data()
|
|
|
|
})
|
|
|
|
|
2024-12-09 14:00:44 +01:00
|
|
|
data_redcap <- m_redcap_readServer(
|
|
|
|
id = "redcap_import",
|
|
|
|
output.format = "list"
|
|
|
|
)
|
|
|
|
|
2024-12-16 22:21:54 +01:00
|
|
|
shiny::observeEvent(data_redcap(), {
|
|
|
|
rv$data_original <- purrr::pluck(data_redcap(), "data")()
|
|
|
|
})
|
|
|
|
|
2024-12-09 14:00:44 +01:00
|
|
|
output$redcap_prev <- DT::renderDT(
|
|
|
|
{
|
2024-12-13 13:37:19 +01:00
|
|
|
DT::datatable(head(purrr::pluck(data_redcap(), "data")(), 5),
|
2024-12-09 14:00:44 +01:00
|
|
|
caption = "First 5 observations"
|
|
|
|
)
|
|
|
|
},
|
|
|
|
server = TRUE
|
|
|
|
)
|
|
|
|
|
2024-12-16 22:21:54 +01:00
|
|
|
from_env <- import_globalenv_server(
|
|
|
|
id = "env",
|
|
|
|
trigger_return = "change",
|
|
|
|
btn_show_data = FALSE,
|
|
|
|
reset = reactive(input$hidden)
|
|
|
|
)
|
2024-12-13 13:37:19 +01:00
|
|
|
|
2024-12-16 22:21:54 +01:00
|
|
|
shiny::observeEvent(from_env$data(), {
|
|
|
|
shiny::req(from_env$data())
|
|
|
|
rv$data_original <- from_env$data()
|
|
|
|
})
|
2024-12-13 13:37:19 +01:00
|
|
|
|
2024-12-09 14:00:44 +01:00
|
|
|
ds <- shiny::reactive({
|
|
|
|
# input$file1 will be NULL initially. After the user selects
|
|
|
|
# and uploads a file, head of that data file by default,
|
|
|
|
# or all rows if selected, will be shown.
|
2024-12-16 22:21:54 +01:00
|
|
|
# if (v$input) {
|
|
|
|
# out <- webResearch_data
|
|
|
|
# } else if (input$source == "file") {
|
|
|
|
# req(data_file$data())
|
|
|
|
# out <- data_file$data()
|
|
|
|
# } else if (input$source == "redcap") {
|
|
|
|
# req(purrr::pluck(data_redcap(), "data")())
|
|
|
|
# out <- purrr::pluck(data_redcap(), "data")()
|
2024-12-09 14:00:44 +01:00
|
|
|
# }
|
2024-12-16 22:21:54 +01:00
|
|
|
|
|
|
|
req(rv$data_original)
|
|
|
|
rv$data_original <- rv$data_original |>
|
2024-12-13 13:37:19 +01:00
|
|
|
REDCapCAST::parse_data() |>
|
|
|
|
REDCapCAST::as_factor() |>
|
|
|
|
REDCapCAST::numchar2fct()
|
|
|
|
|
2024-12-16 22:21:54 +01:00
|
|
|
rv$ds <- "loaded"
|
2024-12-09 14:00:44 +01:00
|
|
|
|
2024-12-16 22:21:54 +01:00
|
|
|
rv$data <- rv$data_original
|
2024-12-13 13:37:19 +01:00
|
|
|
|
2024-12-16 22:21:54 +01:00
|
|
|
rv$data_original
|
|
|
|
})
|
2024-12-13 13:37:19 +01:00
|
|
|
|
|
|
|
##############################################################################
|
|
|
|
#########
|
|
|
|
######### Data modification section
|
|
|
|
#########
|
|
|
|
##############################################################################
|
|
|
|
|
|
|
|
######### Modifications
|
|
|
|
|
2024-12-16 22:21:54 +01:00
|
|
|
shiny::observeEvent(rv$data_original, rv$data <- rv$data_original)
|
|
|
|
shiny::observeEvent(input$data_reset, rv$data <- rv$data_original)
|
2024-12-13 13:37:19 +01:00
|
|
|
|
|
|
|
## Using modified version of the datamods::cut_variable_server function
|
|
|
|
## Further modifications are needed to have cut/bin options based on class of variable
|
|
|
|
## Could be defined server-side
|
2024-12-16 22:21:54 +01:00
|
|
|
shiny::observeEvent(input$modal_cut, modal_cut_variable("modal_cut"))
|
2024-12-13 13:37:19 +01:00
|
|
|
data_modal_cut <- cut_variable_server(
|
|
|
|
id = "modal_cut",
|
2024-12-16 22:21:54 +01:00
|
|
|
data_r = shiny::reactive(rv$data)
|
2024-12-13 13:37:19 +01:00
|
|
|
)
|
2024-12-16 22:21:54 +01:00
|
|
|
shiny::observeEvent(data_modal_cut(), rv$data <- data_modal_cut())
|
2024-12-13 13:37:19 +01:00
|
|
|
|
|
|
|
|
2024-12-16 22:21:54 +01:00
|
|
|
shiny::observeEvent(input$modal_update, datamods::modal_update_factor("modal_update"))
|
2024-12-13 13:37:19 +01:00
|
|
|
data_modal_update <- datamods::update_factor_server(
|
|
|
|
id = "modal_update",
|
|
|
|
data_r = reactive(rv$data)
|
|
|
|
)
|
2024-12-16 22:21:54 +01:00
|
|
|
shiny::observeEvent(data_modal_update(), {
|
2024-12-13 13:37:19 +01:00
|
|
|
shiny::removeModal()
|
|
|
|
rv$data <- data_modal_update()
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Show result
|
2024-12-16 22:21:54 +01:00
|
|
|
output$table_mod <- toastui::renderDatagrid({
|
|
|
|
shiny::req(rv$data)
|
2024-12-13 13:37:19 +01:00
|
|
|
# data <- rv$data
|
|
|
|
toastui::datagrid(
|
2024-12-16 22:21:54 +01:00
|
|
|
# data = rv$data # ,
|
|
|
|
data = data_filter()
|
2024-12-13 13:37:19 +01:00
|
|
|
# bordered = TRUE,
|
|
|
|
# compact = TRUE,
|
|
|
|
# striped = TRUE
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
output$code <- renderPrint({
|
|
|
|
attr(rv$data, "code")
|
|
|
|
})
|
|
|
|
|
|
|
|
updated_data <- datamods::update_variables_server(
|
|
|
|
id = "vars_update",
|
|
|
|
data = reactive(rv$data),
|
|
|
|
return_data_on_init = FALSE
|
|
|
|
)
|
|
|
|
|
|
|
|
output$original_str <- renderPrint({
|
2024-12-17 11:30:17 +01:00
|
|
|
str(rv$data_original)
|
2024-12-13 13:37:19 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
output$modified_str <- renderPrint({
|
|
|
|
str(rv$data)
|
|
|
|
})
|
|
|
|
|
|
|
|
observeEvent(updated_data(), {
|
|
|
|
rv$data <- updated_data()
|
|
|
|
})
|
|
|
|
|
|
|
|
# IDEAFilter has the least cluttered UI, but might have a License issue
|
|
|
|
data_filter <- IDEAFilter::IDEAFilter("data_filter", data = reactive(rv$data), verbose = TRUE)
|
|
|
|
|
2024-12-16 22:21:54 +01:00
|
|
|
# shiny::observeEvent(data_filter(), {
|
|
|
|
# rv$data_filtered <- data_filter()
|
|
|
|
# })
|
2024-12-13 13:37:19 +01:00
|
|
|
|
|
|
|
output$filtered_code <- shiny::renderPrint({
|
2024-12-16 22:21:54 +01:00
|
|
|
cat(gsub(
|
|
|
|
"%>%", "|> \n ",
|
|
|
|
gsub(
|
|
|
|
"\\s{2,}", " ",
|
|
|
|
gsub(
|
|
|
|
"reactive(rv$data)", "data",
|
|
|
|
paste0(
|
|
|
|
capture.output(attr(data_filter(), "code")),
|
|
|
|
collapse = " "
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
))
|
2024-12-13 13:37:19 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
##############################################################################
|
|
|
|
#########
|
|
|
|
######### Data analyses section
|
|
|
|
#########
|
|
|
|
##############################################################################
|
|
|
|
|
|
|
|
## Keep these "old" selection options as a simple alternative to the modification pane
|
|
|
|
|
2024-12-09 14:00:44 +01:00
|
|
|
output$include_vars <- shiny::renderUI({
|
2024-12-13 13:37:19 +01:00
|
|
|
shiny::selectizeInput(
|
2024-12-09 14:00:44 +01:00
|
|
|
inputId = "include_vars",
|
|
|
|
selected = NULL,
|
|
|
|
label = "Covariables to include",
|
2024-12-16 22:21:54 +01:00
|
|
|
choices = colnames(data_filter()),
|
2024-12-09 14:00:44 +01:00
|
|
|
multiple = TRUE
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
output$outcome_var <- shiny::renderUI({
|
2024-12-13 13:37:19 +01:00
|
|
|
shiny::selectInput(
|
2024-12-09 14:00:44 +01:00
|
|
|
inputId = "outcome_var",
|
|
|
|
selected = NULL,
|
|
|
|
label = "Select outcome variable",
|
2024-12-16 22:21:54 +01:00
|
|
|
choices = colnames(data_filter()),
|
2024-12-09 14:00:44 +01:00
|
|
|
multiple = FALSE
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
output$factor_vars <- shiny::renderUI({
|
2024-12-13 13:37:19 +01:00
|
|
|
shiny::selectizeInput(
|
2024-12-09 14:00:44 +01:00
|
|
|
inputId = "factor_vars",
|
2024-12-16 22:21:54 +01:00
|
|
|
selected = colnames(data_filter())[sapply(data_filter(), is.factor)],
|
2024-12-09 14:00:44 +01:00
|
|
|
label = "Covariables to format as categorical",
|
2024-12-16 22:21:54 +01:00
|
|
|
choices = colnames(data_filter()),
|
2024-12-09 14:00:44 +01:00
|
|
|
multiple = TRUE
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
base_vars <- shiny::reactive({
|
|
|
|
if (is.null(input$include_vars)) {
|
2024-12-16 22:21:54 +01:00
|
|
|
out <- colnames(data_filter())
|
2024-12-09 14:00:44 +01:00
|
|
|
} else {
|
|
|
|
out <- unique(c(input$include_vars, input$outcome_var))
|
|
|
|
}
|
|
|
|
return(out)
|
|
|
|
})
|
|
|
|
|
2024-12-16 22:21:54 +01:00
|
|
|
output$strat_var <- shiny::renderUI({
|
|
|
|
shiny::selectInput(
|
|
|
|
inputId = "strat_var",
|
|
|
|
selected = "none",
|
|
|
|
label = "Select variable to stratify baseline",
|
|
|
|
choices = c("none", colnames(data_filter()[base_vars()])),
|
|
|
|
multiple = FALSE
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2024-12-09 14:00:44 +01:00
|
|
|
## Have a look at column filters at some point
|
|
|
|
## There should be a way to use the filtering the filter data for further analyses
|
|
|
|
## Disabled for now, as the JS is apparently not isolated
|
2024-12-17 11:30:17 +01:00
|
|
|
# output$data_table <-
|
|
|
|
# DT::renderDT(
|
|
|
|
# {
|
|
|
|
# DT::datatable(ds()[base_vars()])
|
|
|
|
# },
|
|
|
|
# server = FALSE
|
|
|
|
# )
|
|
|
|
#
|
|
|
|
# output$data.classes <- gt::render_gt({
|
|
|
|
# shiny::req(input$file)
|
|
|
|
# data.frame(matrix(sapply(ds(), \(.x){
|
|
|
|
# class(.x)[1]
|
|
|
|
# }), nrow = 1)) |>
|
|
|
|
# stats::setNames(names(ds())) |>
|
|
|
|
# gt::gt()
|
|
|
|
# })
|
2024-12-09 14:00:44 +01:00
|
|
|
|
|
|
|
shiny::observeEvent(input$act_start, {
|
2024-12-17 11:30:17 +01:00
|
|
|
bslib::nav_select(id = "main_panel", selected = "Modifications")
|
2024-12-09 14:00:44 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
shiny::observeEvent(
|
|
|
|
{
|
|
|
|
input$load
|
|
|
|
},
|
|
|
|
{
|
|
|
|
shiny::req(input$outcome_var)
|
2024-12-13 13:37:19 +01:00
|
|
|
# browser()
|
2024-12-09 14:00:44 +01:00
|
|
|
# Assumes all character variables can be formatted as factors
|
2024-12-13 13:37:19 +01:00
|
|
|
# data <- data_filter$filtered() |>
|
2024-12-18 15:46:02 +01:00
|
|
|
tryCatch(
|
|
|
|
{
|
|
|
|
data <- data_filter() |>
|
|
|
|
dplyr::mutate(dplyr::across(dplyr::where(is.character), as.factor)) |>
|
|
|
|
REDCapCAST::fct_drop.data.frame() |>
|
|
|
|
factorize(vars = input$factor_vars)
|
|
|
|
|
|
|
|
if (input$strat_var == "none") {
|
|
|
|
by.var <- NULL
|
|
|
|
} else {
|
|
|
|
by.var <- input$strat_var
|
|
|
|
}
|
|
|
|
|
|
|
|
data <- data[base_vars()]
|
|
|
|
|
|
|
|
# model <- data |>
|
|
|
|
# regression_model(
|
|
|
|
# outcome.str = input$outcome_var,
|
|
|
|
# auto.mode = input$regression_auto == 1,
|
|
|
|
# formula.str = input$regression_formula,
|
|
|
|
# fun = input$regression_fun,
|
|
|
|
# args.list = eval(parse(text = paste0("list(", input$regression_args, ")")))
|
|
|
|
# )
|
|
|
|
|
|
|
|
models <- list(
|
|
|
|
"Univariable" = regression_model_uv,
|
|
|
|
"Multivariable" = regression_model
|
2024-12-09 14:00:44 +01:00
|
|
|
) |>
|
2024-12-18 15:46:02 +01:00
|
|
|
lapply(\(.fun){
|
|
|
|
do.call(
|
|
|
|
.fun,
|
|
|
|
c(
|
|
|
|
list(data = data),
|
|
|
|
list(outcome.str = input$outcome_var),
|
|
|
|
list(formula.str = input$regression_formula),
|
|
|
|
list(fun = input$regression_fun),
|
|
|
|
list(args.list = eval(parse(text = paste0("list(", input$regression_args, ")"))))
|
|
|
|
)
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
rv$list$data <- data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rv$list$check <- purrr::pluck(models, "Multivariable") |>
|
|
|
|
performance::check_model()
|
|
|
|
|
|
|
|
rv$list$table1 <- data |>
|
|
|
|
baseline_table(
|
|
|
|
fun.args =
|
|
|
|
list(
|
|
|
|
by = by.var
|
|
|
|
)
|
|
|
|
) |>
|
|
|
|
(\(.x){
|
|
|
|
if (!is.null(by.var)) {
|
|
|
|
.x |> gtsummary::add_overall()
|
|
|
|
} else {
|
|
|
|
.x
|
|
|
|
}
|
|
|
|
})() |>
|
|
|
|
(\(.x){
|
|
|
|
if (input$add_p == "yes") {
|
|
|
|
.x |>
|
|
|
|
gtsummary::add_p() |>
|
|
|
|
gtsummary::bold_p()
|
|
|
|
} else {
|
|
|
|
.x
|
|
|
|
}
|
|
|
|
})()
|
|
|
|
|
|
|
|
rv$list$table2 <- models |>
|
|
|
|
purrr::map(regression_table) |>
|
|
|
|
tbl_merge()
|
|
|
|
|
|
|
|
|
|
|
|
rv$list$input <- input
|
|
|
|
|
|
|
|
|
|
|
|
# rv$list <- list(
|
|
|
|
# data = data,
|
|
|
|
# check = check,
|
|
|
|
# table1 = data |>
|
|
|
|
# baseline_table(
|
|
|
|
# fun.args =
|
|
|
|
# list(
|
|
|
|
# by = by.var
|
|
|
|
# )
|
|
|
|
# ) |>
|
|
|
|
# (\(.x){
|
|
|
|
# if (!is.null(by.var)) {
|
|
|
|
# .x |> gtsummary::add_overall()
|
|
|
|
# } else {
|
|
|
|
# .x
|
|
|
|
# }
|
|
|
|
# })() |>
|
|
|
|
# (\(.x){
|
|
|
|
# if (input$add_p == "yes") {
|
|
|
|
# .x |>
|
|
|
|
# gtsummary::add_p() |>
|
|
|
|
# gtsummary::bold_p()
|
|
|
|
# } else {
|
|
|
|
# .x
|
|
|
|
# }
|
|
|
|
# })(),
|
|
|
|
# table2 = models |>
|
|
|
|
# purrr::map(regression_table) |>
|
|
|
|
# tbl_merge(),
|
|
|
|
# input = input
|
|
|
|
# )
|
|
|
|
|
|
|
|
output$table1 <- gt::render_gt(
|
|
|
|
rv$list$table1 |>
|
|
|
|
gtsummary::as_gt()
|
|
|
|
)
|
2024-12-09 14:00:44 +01:00
|
|
|
|
2024-12-18 15:46:02 +01:00
|
|
|
output$table2 <- gt::render_gt(
|
|
|
|
rv$list$table2 |>
|
|
|
|
gtsummary::as_gt()
|
|
|
|
)
|
2024-12-09 14:00:44 +01:00
|
|
|
|
2024-12-18 15:46:02 +01:00
|
|
|
output$check <- shiny::renderPlot({
|
|
|
|
p <- plot(rv$list$check) +
|
|
|
|
patchwork::plot_annotation(title = "Multivariable regression model checks")
|
|
|
|
p
|
|
|
|
# Generate checks in one column
|
|
|
|
# layout <- sapply(seq_len(length(p)), \(.x){
|
|
|
|
# patchwork::area(.x, 1)
|
|
|
|
# })
|
|
|
|
#
|
|
|
|
# p + patchwork::plot_layout(design = Reduce(c, layout))
|
|
|
|
|
|
|
|
# patchwork::wrap_plots(ncol=1) +
|
|
|
|
# patchwork::plot_annotation(title = 'Multivariable regression model checks')
|
|
|
|
})
|
|
|
|
},
|
|
|
|
warning = function(warn) {
|
|
|
|
showNotification(paste0(warn), type = "warning")
|
|
|
|
},
|
|
|
|
error = function(err) {
|
|
|
|
showNotification(paste0("There was the following error. Inspect your data and adjust settings. Error: ",err), type = "err")
|
|
|
|
}
|
2024-12-09 14:00:44 +01:00
|
|
|
)
|
2024-12-18 15:46:02 +01:00
|
|
|
rv$ready <- "ready"
|
2024-12-09 14:00:44 +01:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2024-12-16 22:21:54 +01:00
|
|
|
shiny::conditionalPanel(
|
|
|
|
condition = "output.uploaded == 'yes'",
|
|
|
|
)
|
|
|
|
|
|
|
|
# observeEvent(input$act_start, {
|
|
|
|
# nav_show(id = "overview",target = "Import"
|
|
|
|
# )
|
|
|
|
# })
|
|
|
|
|
2024-12-09 14:00:44 +01:00
|
|
|
|
|
|
|
|
|
|
|
output$uploaded <- shiny::reactive({
|
2024-12-16 22:21:54 +01:00
|
|
|
if (is.null(rv$ds)) {
|
2024-12-09 14:00:44 +01:00
|
|
|
"no"
|
|
|
|
} else {
|
|
|
|
"yes"
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
shiny::outputOptions(output, "uploaded", suspendWhenHidden = FALSE)
|
|
|
|
|
2024-12-18 11:26:00 +01:00
|
|
|
output$ready <- shiny::reactive({
|
|
|
|
if (is.null(rv$ready)) {
|
|
|
|
"no"
|
|
|
|
} else {
|
|
|
|
"yes"
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
shiny::outputOptions(output, "ready", suspendWhenHidden = FALSE)
|
2024-12-09 14:00:44 +01:00
|
|
|
|
2024-12-16 22:21:54 +01:00
|
|
|
# Reimplement from environment at later time
|
|
|
|
# output$has_input <- shiny::reactive({
|
|
|
|
# if (rv$input) {
|
|
|
|
# "yes"
|
|
|
|
# } else {
|
|
|
|
# "no"
|
|
|
|
# }
|
|
|
|
# })
|
|
|
|
|
|
|
|
# shiny::outputOptions(output, "has_input", suspendWhenHidden = FALSE)
|
2024-12-09 14:00:44 +01:00
|
|
|
|
|
|
|
# Could be rendered with other tables or should show progress
|
|
|
|
# Investigate quarto render problems
|
|
|
|
# On temp file handling: https://github.com/quarto-dev/quarto-cli/issues/3992
|
|
|
|
output$report <- downloadHandler(
|
|
|
|
filename = shiny::reactive({
|
|
|
|
paste0("report.", input$output_type)
|
|
|
|
}),
|
|
|
|
content = function(file, type = input$output_type) {
|
|
|
|
## Notification is not progressing
|
|
|
|
## Presumably due to missing
|
2024-12-18 11:26:00 +01:00
|
|
|
shiny::withProgress(message = "Generating the report. Hold on for a moment..", {
|
2024-12-16 22:21:54 +01:00
|
|
|
rv$list |>
|
2024-12-09 14:00:44 +01:00
|
|
|
write_quarto(
|
|
|
|
output_format = type,
|
|
|
|
input = file.path(getwd(), "www/report.qmd")
|
|
|
|
)
|
|
|
|
})
|
|
|
|
file.rename(paste0("www/report.", type), file)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
session$onSessionEnded(function() {
|
|
|
|
cat("Session Ended\n")
|
|
|
|
files <- list.files("www/")
|
|
|
|
lapply(files[!files %in% files.to.keep], \(.x){
|
|
|
|
unlink(paste0("www/", .x), recursive = FALSE)
|
|
|
|
print(paste(.x, "deleted"))
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|