updated vignette and formatting

This commit is contained in:
Andreas Gammelgaard Damsbo 2024-11-18 16:26:10 +01:00
commit 4e7af7d01f
No known key found for this signature in database
5 changed files with 97 additions and 33 deletions

View file

@ -1,4 +1,3 @@
library(REDCapCAST)
library(bslib)
library(shiny)
library(openxlsx2)
@ -7,9 +6,14 @@ library(readODS)
library(readr)
library(dplyr)
library(here)
library(devtools)
if (!requireNamespace("REDCapCAST")){
devtools::install_github("agdamsbo/REDCapCAST", quiet = TRUE, upgrade = "never")
}
library(REDCapCAST)
server <- function(input, output, session) {
v <- shiny::reactiveValues(
file = NULL
)
@ -64,7 +68,7 @@ server <- function(input, output, session) {
output$downloadData <- shiny::downloadHandler(
filename = "data_ready.csv",
content = function(file) {
write.csv(purrr::pluck(dd(), "data"), file, row.names = FALSE,na = "")
write.csv(purrr::pluck(dd(), "data"), file, row.names = FALSE, na = "")
}
)
@ -72,13 +76,13 @@ server <- function(input, output, session) {
output$downloadMeta <- shiny::downloadHandler(
filename = "datadictionary_ready.csv",
content = function(file) {
write.csv(purrr::pluck(dd(), "meta"), file, row.names = FALSE,na = "")
write.csv(purrr::pluck(dd(), "meta"), file, row.names = FALSE, na = "")
}
)
# Downloadable .zip of instrument ----
output$downloadInstrument <- shiny::downloadHandler(
filename = paste0("REDCapCAST_instrument",Sys.Date(),".zip"),
filename = paste0("REDCapCAST_instrument", Sys.Date(), ".zip"),
content = function(file) {
export_redcap_instrument(purrr::pluck(dd(), "meta"), file)
}
@ -88,12 +92,15 @@ server <- function(input, output, session) {
output_staging$meta <- output_staging$data <- NA
shiny::observeEvent(input$upload.meta,{ upload_meta() })
shiny::observeEvent(input$upload.meta, {
upload_meta()
})
shiny::observeEvent(input$upload.data,{ upload_data() })
upload_meta <- function(){
shiny::observeEvent(input$upload.data, {
upload_data()
})
upload_meta <- function() {
shiny::req(input$uri)
shiny::req(input$api)
@ -102,11 +109,10 @@ server <- function(input, output, session) {
ds = purrr::pluck(dd(), "meta"),
redcap_uri = input$uri,
token = input$api
)|> purrr::pluck("success")
) |> purrr::pluck("success")
}
upload_data <- function(){
upload_data <- function() {
shiny::req(input$uri)
shiny::req(input$api)
@ -122,4 +128,8 @@ server <- function(input, output, session) {
output$upload.data.print <- renderText(output_staging$data)
# session$onSessionEnded(function() {
# # cat("Session Ended\n")
# unlink("www",recursive = TRUE)
# })
}

View file

@ -19,20 +19,27 @@ ui <-
".ods"
)
),
shiny::helpText("Have a look at the preview panels to show download options."),
shiny::actionButton(
inputId = "load_data",
label = "Load data",
icon = shiny::icon("circle-down")
),
shiny::helpText("Have a look at the preview panels to validate the data dictionary and imported data."),
# For some odd reason this only unfolds when the preview panel is shown..
# This has been solved by adding an arbitrary button to load data
shiny::conditionalPanel(
condition = "output.uploaded=='yes'",
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."),
# condition = "output.uploaded=='yes'",
condition = "input.load_data",
# 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 renamed data"),
shiny::downloadButton(outputId = "downloadData", label = "Download renamed data"),
# Button
shiny::downloadButton("downloadMeta", "Download data dictionary"),
shiny::downloadButton(outputId = "downloadMeta", label = "Download data dictionary"),
# Button
shiny::downloadButton("downloadInstrument", "Download as instrument"),
shiny::downloadButton(outputId = "downloadInstrument", label = "Download as instrument"),
# Horizontal line ----
shiny::tags$hr(),
@ -108,3 +115,4 @@ ui <-
)
)
)