Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add summary #80

Merged
merged 9 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions R/appStatic.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#' @param logo Name of a logo or path to a logo. If NULL no logo is included.
#' Only svg format allowed for the moment.
#' @param title title of the shiny
#' @param summary Whether to include a panel with a summary of content in the
#' `result`.
#' @param open Whether to open the shiny app project.
#'
#' @return The shiny app will be created in directory.
Expand All @@ -14,6 +16,7 @@
exportStaticApp <- function(result = emptySummarisedResult(),
logo = "HDS",
title = "My study",
summary = TRUE,
directory = getwd(),
open = rlang::is_interactive()) {
# input check
Expand All @@ -22,6 +25,12 @@
omopgenerics::assertLogical(open, length = 1)
omopgenerics::assertCharacter(logo, length = 1, null = TRUE)
omopgenerics::assertCharacter(title, length = 1)
omopgenerics::assertLogical(summary, length = 1)
if (summary) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we have this in an internal function? Then if we expand is easier to deal with it?

sum <- capture.output(summary(result), type = "message")
} else {
sum <- NULL

Check warning on line 32 in R/appStatic.R

View check run for this annotation

Codecov / codecov/patch

R/appStatic.R#L32

Added line #L32 was not covered by tests
}

# create directory if it does not exit
if (!dir.exists(directory)) {
Expand Down Expand Up @@ -52,7 +61,7 @@
dir.create(path = directory, showWarnings = FALSE)
cli::cli_inform(c("i" = "Creating shiny from provided data"))
logo <- copyLogos(logo, directory)
ui <- c(messageShiny(), uiStatic(choices = choices, logo = logo, title = title))
ui <- c(messageShiny(), uiStatic(choices = choices, logo = logo, title = title, summary = sum))
server <- c(messageShiny(), serverStatic(resultTypes = names(choices)))
global <- c(messageShiny(), omopViewerGlobal)
dir.create(paste0(directory, "/data"), showWarnings = FALSE)
Expand Down Expand Up @@ -111,7 +120,8 @@
uiStatic <- function(choices = list(),
logo = NULL,
title = "My study",
background = TRUE) {
background = TRUE,
summary = NULL) {
# initial checks
omopgenerics::assertList(choices, named = TRUE)
omopgenerics::assertCharacter(logo, length = 1, null = TRUE)
Expand All @@ -123,6 +133,7 @@
c(
pageTitle(title, logo),
createBackground(background, title, logo),
createSummary(summary, logo),
createUi(names(choices), choices),
'bslib::nav_spacer()',
createAbout("hds_logo.svg"),
Expand Down
40 changes: 40 additions & 0 deletions R/summary.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
createSummary <- function(sum, logo) {
if (length(sum) == 0) {return("")}

if (!is.null(logo)) {
logoImg <- ',
shiny::tags$img(
src = "{logo}",
width = "auto",
height = "100px",
alt = "logo",
align = "left"
)' |>
glue::glue() |>
as.character()
} else {
logoImg <- ""
}

return(
'bslib::nav_panel(
title = "Summary",
icon = shiny::icon("file-alt"),
bslib::card(
bslib::card_header("Summary of results"),
{styleSummary(sum)}
{logoImg}
)
)' |>
glue::glue() |>
as.character()
)
}

styleSummary <- function(sum) {
sum[1] <- gsub("(\\d+)", "**\\1**", sum[1])
sum[-1] <- paste0(" - **", gsub(": ", ":** ", sum[-1]))
purrr::map(sum, function(x){
glue::glue('shiny::p(shiny::markdown("{x}"))')
}) |> unlist() |> paste0(collapse = ", ")
}
4 changes: 4 additions & 0 deletions man/exportStaticApp.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading