From f09439493380518de4fd737025baeb95dbd94ff8 Mon Sep 17 00:00:00 2001 From: Andreas Gammelgaard Damsbo Date: Wed, 20 Nov 2024 16:25:26 +0100 Subject: [PATCH] moving functions from app to fix dependencies --- DESCRIPTION | 11 +- NAMESPACE | 1 + R/shiny_cast.R | 149 +++++++++++++++++- .../shinyapps.io/agdamsbo/redcapcast.dcf | 2 +- inst/shiny-examples/casting/server.R | 1 - inst/shiny-examples/casting/ui.R | 139 +--------------- man/nav_bar_page.Rd | 14 ++ 7 files changed, 170 insertions(+), 147 deletions(-) create mode 100644 man/nav_bar_page.Rd diff --git a/DESCRIPTION b/DESCRIPTION index d71ae08..8a9a354 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -29,15 +29,11 @@ Suggests: Hmisc, knitr, rmarkdown, - ggplot2, - here, styler, devtools, roxygen2, spelling, - glue, - rhub, - bslib + rhub License: GPL (>= 3) Encoding: UTF-8 LazyData: true @@ -61,7 +57,10 @@ Imports: readODS, forcats, vctrs, - gt + gt, + bslib, + here, + glue Collate: 'REDCapCAST-package.R' 'utils.r' diff --git a/NAMESPACE b/NAMESPACE index b8b67b5..b9939b2 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -39,6 +39,7 @@ export(html_tag_wrap) export(is_repeated_longitudinal) export(match_fields_to_form) export(named_levels) +export(nav_bar_page) export(numchar2fct) export(parse_data) export(process_user_input) diff --git a/R/shiny_cast.R b/R/shiny_cast.R index 5407aad..eb28174 100644 --- a/R/shiny_cast.R +++ b/R/shiny_cast.R @@ -89,7 +89,7 @@ cast_data_overview <- function(data){ stopifnot("REDCapCAST" %in% class(data)) data |> purrr::pluck("data") |> - head(20) |> + utils::head(20) |> # dplyr::tibble() |> gt::gt() |> gt::tab_style( @@ -144,3 +144,150 @@ cast_meta_overview <- function(data){ ) ) } + + +#' Nav_bar defining function for shiny ui +#' +#' @return shiny object +#' @export +#' +nav_bar_page <- function(){ + bslib::page_navbar( + title = "Easy REDCap database creation", + sidebar = bslib::sidebar( + width = 300, + shiny::h5("Metadata casting"), + shiny::fileInput( + inputId = "ds", + label = "Upload spreadsheet", + multiple = FALSE, + accept = c( + ".csv", + ".xls", + ".xlsx", + ".dta", + ".rds", + ".ods" + ) + ), + # 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 - which was abandoned again + shiny::conditionalPanel( + condition = "output.uploaded=='yes'", + shiny::radioButtons( + inputId = "add_id", + label = "Add ID, or use first column?", + selected = "no", + inline = TRUE, + choices = list( + "First column" = "no", + "Add ID" = "yes", + "No ID" = "none" + ) + ), + shiny::radioButtons( + inputId = "specify_factors", + label = "Specify categorical variables?", + selected = "no", + inline = TRUE, + choices = list( + "No" = "no", + "Yes" = "yes" + ) + ), + shiny::conditionalPanel( + condition = "input.specify_factors=='yes'", + shiny::uiOutput("factor_vars") + ), + # 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(outputId = "downloadData", label = "Download renamed data"), + + # Button + shiny::downloadButton(outputId = "downloadMeta", label = "Download data dictionary"), + + # Button + shiny::downloadButton(outputId = "downloadInstrument", label = "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" + ) + ), + 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") + ), + shiny::p( + 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_panel( + title = "Data preview", + gt::gt_output(outputId = "data.tbl") + # shiny::htmlOutput(outputId = "data.tbl", container = shiny::span) + ), + bslib::nav_panel( + title = "Dictionary overview", + 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::textOutput(outputId = "upload.meta.print"), + shiny::h3("Data upload overview"), + shiny::textOutput(outputId = "upload.data.print") + ) + ) +} diff --git a/inst/shiny-examples/casting/rsconnect/shinyapps.io/agdamsbo/redcapcast.dcf b/inst/shiny-examples/casting/rsconnect/shinyapps.io/agdamsbo/redcapcast.dcf index c653183..c22cdf3 100644 --- a/inst/shiny-examples/casting/rsconnect/shinyapps.io/agdamsbo/redcapcast.dcf +++ b/inst/shiny-examples/casting/rsconnect/shinyapps.io/agdamsbo/redcapcast.dcf @@ -5,6 +5,6 @@ account: agdamsbo server: shinyapps.io hostUrl: https://api.shinyapps.io/v1 appId: 11351429 -bundleId: 9392220 +bundleId: 9392320 url: https://agdamsbo.shinyapps.io/redcapcast/ version: 1 diff --git a/inst/shiny-examples/casting/server.R b/inst/shiny-examples/casting/server.R index da4edf4..7fe60ba 100644 --- a/inst/shiny-examples/casting/server.R +++ b/inst/shiny-examples/casting/server.R @@ -5,7 +5,6 @@ library(haven) library(readODS) library(readr) library(dplyr) -library(here) library(devtools) if (!requireNamespace("REDCapCAST")) { devtools::install_github("agdamsbo/REDCapCAST", quiet = TRUE, upgrade = "never") diff --git a/inst/shiny-examples/casting/ui.R b/inst/shiny-examples/casting/ui.R index 41aa3a6..221d54b 100644 --- a/inst/shiny-examples/casting/ui.R +++ b/inst/shiny-examples/casting/ui.R @@ -2,143 +2,6 @@ ui <- bslib::page( theme = bslib::bs_theme(preset = "united"), title = "REDCap database creator", - bslib::page_navbar( - title = "Easy REDCap database creation", - sidebar = bslib::sidebar( - width = 300, - shiny::h5("Metadata casting"), - shiny::fileInput( - inputId = "ds", - label = "Upload spreadsheet", - multiple = FALSE, - accept = c( - ".csv", - ".xls", - ".xlsx", - ".dta", - ".rds", - ".ods" - ) - ), - # 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 - which was abandoned again - shiny::conditionalPanel( - condition = "output.uploaded=='yes'", - shiny::radioButtons( - inputId = "add_id", - label = "Add ID, or use first column?", - selected = "no", - inline = TRUE, - choices = list( - "First column" = "no", - "Add ID" = "yes", - "No ID" = "none" - ) - ), - shiny::radioButtons( - inputId = "specify_factors", - label = "Specify categorical variables?", - selected = "no", - inline = TRUE, - choices = list( - "No" = "no", - "Yes" = "yes" - ) - ), - shiny::conditionalPanel( - condition = "input.specify_factors=='yes'", - uiOutput("factor_vars") - ), - # 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(outputId = "downloadData", label = "Download renamed data"), - - # Button - shiny::downloadButton(outputId = "downloadMeta", label = "Download data dictionary"), - - # Button - shiny::downloadButton(outputId = "downloadInstrument", label = "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" - ) - ), - 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") - ), - shiny::p( - 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_panel( - title = "Data preview", - gt::gt_output(outputId = "data.tbl") - # shiny::htmlOutput(outputId = "data.tbl", container = shiny::span) - ), - bslib::nav_panel( - title = "Dictionary overview", - 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::textOutput(outputId = "upload.meta.print"), - shiny::h3("Data upload overview"), - shiny::textOutput(outputId = "upload.data.print") - ) - ) +nav_bar_page() ) diff --git a/man/nav_bar_page.Rd b/man/nav_bar_page.Rd new file mode 100644 index 0000000..5953e2b --- /dev/null +++ b/man/nav_bar_page.Rd @@ -0,0 +1,14 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/shiny_cast.R +\name{nav_bar_page} +\alias{nav_bar_page} +\title{Nav_bar defining function for shiny ui} +\usage{ +nav_bar_page() +} +\value{ +shiny object +} +\description{ +Nav_bar defining function for shiny ui +}