Skip to content

Commit

Permalink
Merge pull request #131 from oxford-pharmacoepi/issue_120
Browse files Browse the repository at this point in the history
add download raw button
  • Loading branch information
catalamarti authored Oct 3, 2024
2 parents 27471bb + b7cbe07 commit c70122b
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 1 deletion.
2 changes: 1 addition & 1 deletion R/appStatic.R
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ copyLogos <- function(logo, directory) {
return(NULL)
}
}

logoPath <- function(logo) {
lowLogo <- stringr::str_to_lower(logo)
# add more logoKeywords in data-raw/internalData
Expand Down Expand Up @@ -199,6 +198,7 @@ uiStatic <- function(choices = list(),
createSummary(summary, logo),
createUi(names(choices), choices),
"bslib::nav_spacer()",
downloadRawDataUi(),
createAbout("hds_logo.svg"),
'bslib::nav_item(bslib::input_dark_mode(id ="dark_mode", mode = "light"))'
) |>
Expand Down
1 change: 1 addition & 0 deletions R/createServer.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

createServer <- function(resultTypes, data) {
c(
downloadRawDataServer(data),
selectiseServer(resultTypes, data),
purrr::map_chr(resultTypes, \(x) {
c(glue::glue("# {x} -----"),
Expand Down
23 changes: 23 additions & 0 deletions R/panelRaw.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@

# ui ----
downloadRawDataUi <- function() {
'bslib::nav_item(
bslib::popover(
shiny::icon("download"),
shiny::downloadButton(
outputId = "download_raw",
label = "Download raw data",
icon = shiny::icon("download")
)
)
)'
}
rawUi <- function(rt) {
id <- paste0(rt, "_raw_download")
'bslib::nav_panel(
Expand All @@ -15,6 +27,17 @@ rawUi <- function(rt) {
}

# server ----
downloadRawDataServer <- function(data) {
'# download raw data -----
output$download_raw <- shiny::downloadHandler(
filename = "results.csv",
content = function(file) {
omopViewer::exportSummarisedResult([data], fileName = file)
}
)' |>
glue::glue(.open = "[", .close = "]") |>
as.character()
}
rawServer <- function(rt, data) {
c('getRawData[formatCamel(rt)] <- shiny::reactive({
filterData([data], "[rt]", input)
Expand Down
74 changes: 74 additions & 0 deletions tests/testthat/_snaps/appStatic.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@
""
),
bslib::nav_spacer(),
bslib::nav_item(
bslib::popover(
shiny::icon("download"),
shiny::downloadButton(
outputId = "download_raw",
label = "Download raw data",
icon = shiny::icon("download")
)
)
),
bslib::nav_item(
bslib::popover(
shiny::icon("circle-info"),
Expand Down Expand Up @@ -46,6 +56,16 @@
ui <- bslib::page_navbar(
title = "",
bslib::nav_spacer(),
bslib::nav_item(
bslib::popover(
shiny::icon("download"),
shiny::downloadButton(
outputId = "download_raw",
label = "Download raw data",
icon = shiny::icon("download")
)
)
),
bslib::nav_item(
bslib::popover(
shiny::icon("circle-info"),
Expand Down Expand Up @@ -75,6 +95,13 @@
cat(serverStatic(), sep = "\n")
Output
server <- function(input, output, session) {
# download raw data -----
output$download_raw <- shiny::downloadHandler(
filename = "results.csv",
content = function(file) {
omopViewer::exportSummarisedResult(data, fileName = file)
}
)
}

# CohortCharacteristics shiny
Expand Down Expand Up @@ -1393,6 +1420,16 @@
)
),
bslib::nav_spacer(),
bslib::nav_item(
bslib::popover(
shiny::icon("download"),
shiny::downloadButton(
outputId = "download_raw",
label = "Download raw data",
icon = shiny::icon("download")
)
)
),
bslib::nav_item(
bslib::popover(
shiny::icon("circle-info"),
Expand Down Expand Up @@ -1422,6 +1459,13 @@
cat(serverStatic(resultTypes = names(getChoices(result))), sep = "\n")
Output
server <- function(input, output, session) {
# download raw data -----
output$download_raw <- shiny::downloadHandler(
filename = "results.csv",
content = function(file) {
omopViewer::exportSummarisedResult(data, fileName = file)
}
)
# fill selectise variables ----
shiny::observe({
choices <- omopViewer::getChoices(data, flatten = TRUE)
Expand Down Expand Up @@ -3281,6 +3325,16 @@
)
),
bslib::nav_spacer(),
bslib::nav_item(
bslib::popover(
shiny::icon("download"),
shiny::downloadButton(
outputId = "download_raw",
label = "Download raw data",
icon = shiny::icon("download")
)
)
),
bslib::nav_item(
bslib::popover(
shiny::icon("circle-info"),
Expand Down Expand Up @@ -4634,6 +4688,16 @@
)
),
bslib::nav_spacer(),
bslib::nav_item(
bslib::popover(
shiny::icon("download"),
shiny::downloadButton(
outputId = "download_raw",
label = "Download raw data",
icon = shiny::icon("download")
)
)
),
bslib::nav_item(
bslib::popover(
shiny::icon("circle-info"),
Expand Down Expand Up @@ -4706,6 +4770,16 @@
)
),
bslib::nav_spacer(),
bslib::nav_item(
bslib::popover(
shiny::icon("download"),
shiny::downloadButton(
outputId = "download_raw",
label = "Download raw data",
icon = shiny::icon("download")
)
)
),
bslib::nav_item(
bslib::popover(
shiny::icon("circle-info"),
Expand Down

0 comments on commit c70122b

Please sign in to comment.