From 927d485739a4c9bedf9378b2c6244794560e9667 Mon Sep 17 00:00:00 2001 From: Andreas Gammelgaard Damsbo Date: Mon, 18 Nov 2024 08:17:55 +0100 Subject: [PATCH] minor name edit --- DESCRIPTION | 4 +- inst/shiny-examples/casting/server.R | 64 ++++++++++----- inst/shiny-examples/casting/ui.R | 116 ++++++++++++++------------- 3 files changed, 106 insertions(+), 78 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 44fe2de..d231029 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: REDCapCAST -Title: REDCap Castellated Data Handling And Metadata Casting -Version: 24.11.1 +Title: REDCap Castellated Data Handling and Metadata Casting +Version: 24.11.2 Authors@R: c( person("Andreas Gammelgaard", "Damsbo", email = "agdamsbo@clin.au.dk", role = c("aut", "cre"),comment = c(ORCID = "0000-0002-7559-1154")), diff --git a/inst/shiny-examples/casting/server.R b/inst/shiny-examples/casting/server.R index 6371e06..161976d 100644 --- a/inst/shiny-examples/casting/server.R +++ b/inst/shiny-examples/casting/server.R @@ -1,32 +1,63 @@ -server <- function(input, output, session) { - require(REDCapCAST) +library(REDCapCAST) +library(bslib) +library(shiny) +library(openxlsx2) +library(haven) +library(readODS) +library(readr) +library(dplyr) +library(here) - # bslib::bs_themer() +server <- function(input, output, session) { + + v <- shiny::reactiveValues( + file = NULL + ) dat <- shiny::reactive({ shiny::req(input$ds) - output_staging$file <- "loaded" read_input(input$ds$datapath) }) + # getData <- reactive({ + # if(is.null(input$ds$datapath)) return(NULL) + # }) + # output$uploaded <- reactive({ + # return(!is.null(getData())) + # }) + + + output$uploaded <- shiny::reactive({ + if (is.null(v$file)) { + "no" + } else { + "yes" + } + }) + + shiny::outputOptions(output, "uploaded", suspendWhenHidden = FALSE) + dd <- shiny::reactive({ + shiny::req(input$ds) + v$file <- "loaded" ds2dd_detailed(data = dat()) }) - - output$data.tbl <- shiny::renderTable({ + output$data.tbl <- gt::render_gt( dd() |> purrr::pluck("data") |> head(20) |> - dplyr::tibble() - }) + dplyr::tibble() |> + gt::gt() + ) - output$meta.tbl <- shiny::renderTable({ + output$meta.tbl <- gt::render_gt( dd() |> purrr::pluck("meta") |> - dplyr::tibble() - }) + dplyr::tibble() |> + gt::gt() + ) # Downloadable csv of dataset ---- output$downloadData <- shiny::downloadHandler( @@ -53,17 +84,8 @@ server <- function(input, output, session) { ) output_staging <- shiny::reactiveValues() - output_staging$meta <- output_staging$data <- output_staging$file <- NA - output$uploaded <- shiny::reactive({ - if (is.na(output_staging$file)) { - "no" - } else { - "yes" - } - }) - - shiny::outputOptions(output, "uploaded", suspendWhenHidden = FALSE) + output_staging$meta <- output_staging$data <- NA shiny::observeEvent(input$upload.meta,{ upload_meta() }) diff --git a/inst/shiny-examples/casting/ui.R b/inst/shiny-examples/casting/ui.R index 4c7d11a..6288d91 100644 --- a/inst/shiny-examples/casting/ui.R +++ b/inst/shiny-examples/casting/ui.R @@ -4,11 +4,12 @@ ui <- title = "REDCap database creator", bslib::page_navbar( title = "Easy REDCap database creation", - sidebar = bslib::sidebar(width = 300, + sidebar = bslib::sidebar( + width = 300, shiny::h5("1) Database meta data"), shiny::fileInput( inputId = "ds", - label = "Upload spreadsheet", + label = "Upload spreadsheet", multiple = FALSE, accept = c( ".csv", @@ -18,87 +19,92 @@ ui <- ".ods" ) ), - conditionalPanel( + shiny::helpText("Have a look at the preview panels to show download options."), + # For some odd reason this only unfolds when the preview panel is shown.. + shiny::conditionalPanel( condition = "output.uploaded=='yes'", - shiny::helpText("Below you can download the dataset formatted for upload and the + shiny::helpText("Below you can download the dataset formatted for upload and the corresponding data dictionary for a new data base, if you want to upload manually."), - # Button - shiny::downloadButton("downloadData", "Download adjusted data"), + # Button + shiny::downloadButton("downloadData", "Download renamed data"), - # Button - shiny::downloadButton("downloadMeta", "Download data dictionary"), + # Button + shiny::downloadButton("downloadMeta", "Download data dictionary"), - # Button - shiny::downloadButton("downloadInstrument", "Download as instrument"), + # Button + shiny::downloadButton("downloadInstrument", "Download as instrument"), - # Horizontal line ---- - shiny::tags$hr(), - shiny::radioButtons( - inputId = "upload_redcap", - label = "Upload directly to REDCap server?", - selected = "no", - inline = TRUE, - choices = list( - "No" = "no", - "Yes" = "yes" + # Horizontal line ---- + shiny::tags$hr(), + shiny::radioButtons( + inputId = "upload_redcap", + label = "Upload directly to REDCap server?", + selected = "no", + inline = TRUE, + choices = list( + "No" = "no", + "Yes" = "yes" + ) + ), + shiny::conditionalPanel( + condition = "input.upload_redcap=='yes'", + shiny::h4("2) Data base upload"), + shiny::helpText("This tool is usable for now. Detailed instructions are coming."), + shiny::textInput( + inputId = "uri", + label = "URI", + value = "https://redcap.your.institution/api/" + ), + shiny::textInput( + inputId = "api", + label = "API key", + value = "" + ), + shiny::helpText("An API key is an access key to the REDCap database. Please", shiny::a("see here for directions", href = "https://www.iths.org/news/redcap-tip/redcap-api-101/"), " to obtain an API key for your project."), + shiny::actionButton( + inputId = "upload.meta", + label = "Upload datadictionary", icon = shiny::icon("book-bookmark") + ), + shiny::helpText("Please note, that before uploading any real data, put your project + into production mode."), + shiny::actionButton( + inputId = "upload.data", + label = "Upload data", icon = shiny::icon("upload") + ) ) ), - shiny::conditionalPanel( - condition = "input.upload_redcap=='yes'", - shiny::h4("2) Data base upload"), - shiny::helpText("This tool is usable for now. Detailed instructions are coming."), - shiny::textInput( - inputId = "uri", - label = "URI", - value = "https://redcap.your.institution/api/" - ), - shiny::textInput( - inputId = "api", - label = "API key", - value = "" - ), - shiny::helpText("An API key is an access key to the REDCap database. Please", shiny::a("see here for directions", href = "https://www.iths.org/news/redcap-tip/redcap-api-101/"), " to obtain an API key for your project."), - shiny::actionButton( - inputId = "upload.meta", - label = "Upload datadictionary", icon = shiny::icon("book-bookmark") - ), - shiny::helpText("Please note, that before uploading any real data, put your project - into production mode."), - shiny::actionButton( - inputId = "upload.data", - label = "Upload data", icon = shiny::icon("upload") - ) - ) - ), shiny::br(), shiny::br(), shiny::br(), shiny::p( - "License: ",shiny::a("GPL-3+", href = "https://agdamsbo.github.io/REDCapCAST/LICENSE.html")), + "License: ", shiny::a("GPL-3+", href = "https://agdamsbo.github.io/REDCapCAST/LICENSE.html") + ), shiny::p( - shiny::a("Package documentation", href = "https://agdamsbo.github.io/REDCapCAST")) - + shiny::a("Package documentation", href = "https://agdamsbo.github.io/REDCapCAST") + ) ), bslib::nav_panel( title = "Intro", shiny::markdown(readLines("www/SHINYCAST.md")), shiny::br() ), - bslib::nav_spacer(), + # bslib::nav_spacer(), bslib::nav_panel( title = "Data preview", - shiny::htmlOutput(outputId = "data.tbl", container = shiny::span) + gt::gt_output(outputId = "data.tbl") + # shiny::htmlOutput(outputId = "data.tbl", container = shiny::span) ), bslib::nav_panel( title = "Dictionary overview", - shiny::htmlOutput(outputId = "meta.tbl", container = shiny::span) + gt::gt_output(outputId = "meta.tbl") + # shiny::htmlOutput(outputId = "meta.tbl", container = shiny::span) ), bslib::nav_panel( title = "Upload", shiny::h3("Meta upload overview"), - shiny::htmlOutput(outputId = "upload.meta.print", container = shiny::span), + shiny::textOutput(outputId = "upload.meta.print"), shiny::h3("Data upload overview"), - shiny::htmlOutput(outputId = "upload.data.print", container = shiny::span) + shiny::textOutput(outputId = "upload.data.print") ) ) )