Skip to content

Commit

Permalink
Fixing #302 and Filtered Data Downloads (#332)
Browse files Browse the repository at this point in the history
* Fixing #302 and Filtered Data Downloads

All filtered data downloads across all modules should work now, with a button styled the same as the full download. It needs to be a CSV handler though due to the reactable statte

* Updating the fix

Also fixed download buttons in Cohorts module, addressing #298
  • Loading branch information
nhall6 authored Sep 12, 2024
1 parent 842b3aa commit b5bb043
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 79 deletions.
136 changes: 72 additions & 64 deletions R/cohort-generator-main.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,35 +64,41 @@ cohortGeneratorViewer <- function(id) {
collapsible = T,
collapsed = F,
width = '100%',
title = shiny::span( shiny::icon("file-arrow-down"),'Download Data'),
#solidHeader = TRUE,

shiny::downloadButton(
ns('downloadCohortCountsFull'),
label = "Download (Full)",
icon = shiny::icon("download")
),

shiny::actionButton(
ns('downloadCohortCountsFiltered'),
label = "Download (Filtered)",
icon = shiny::icon("download"),
onclick = paste0("Reactable.downloadDataCSV('", ns('cohortCounts'),
"', 'cohort-count-data-filtered-", Sys.Date(), ".csv')")
)
),
# title = shiny::span( shiny::icon("file-arrow-down"),'Download Data'),
# #solidHeader = TRUE,
#
# shiny::downloadButton(
# ns('downloadCohortCountsFull'),
# label = "Download (Full)",
# icon = shiny::icon("download")
# ),
#
# shiny::actionButton(
# ns('downloadCohortCountsFiltered'),
# label = "Download (Filtered)",
# icon = shiny::icon("download"),
# onclick = paste0("Reactable.downloadDataCSV('", ns('cohortCounts'),
# "', 'cohort-count-data-filtered-", Sys.Date(), ".csv')")
# )
# ),

shinydashboard::box(
width = '100%',
title = shiny::span( shiny::icon("table"), 'Counts Table'),
#solidHeader = TRUE,

shiny::uiOutput(ns("selectColsCohortCounts")
),

reactable::reactableOutput(
outputId = ns("cohortCounts")
)
# shinydashboard::box(
# width = '100%',
# title = shiny::span( shiny::icon("table"), 'Counts Table'),
# #solidHeader = TRUE,
#
# shiny::uiOutput(ns("selectColsCohortCounts")
# ),
#
# reactable::reactableOutput(
# outputId = ns("cohortCounts")
# )
# )

resultTableViewer(
ns("cohortCounts"),
downloadedFileName = "cohortCountsTable-"
)
)
),

Expand All @@ -103,29 +109,30 @@ cohortGeneratorViewer <- function(id) {
collapsible = T,
collapsed = F,
width = '100%',
title = shiny::span( shiny::icon("file-arrow-down"),'Download Data'),
#solidHeader = TRUE,
# title = shiny::span( shiny::icon("file-arrow-down"),'Download Data'),
# #solidHeader = TRUE,
#
# shiny::downloadButton(
# ns('downloadCohortGeneration'),
# label = "Download",
# icon = shiny::icon("download")
# )
# ),
#
# shinydashboard::box(
# status = 'info',
# width = '100%',
# title = shiny::span( shiny::icon("table"), 'Generation Table'),
# #solidHeader = TRUE,
#
# shiny::uiOutput(ns("selectColsCohortGeneration")
# ),

shiny::downloadButton(
ns('downloadCohortGeneration'),
label = "Download",
icon = shiny::icon("download")
)
),

shinydashboard::box(
status = 'info',
width = '100%',
title = shiny::span( shiny::icon("table"), 'Generation Table'),
#solidHeader = TRUE,

shiny::uiOutput(ns("selectColsCohortGeneration")
),

reactable::reactableOutput(
outputId = ns("cohortGeneration")
)
resultTableViewer(
ns("cohortGeneration"),
downloadedFileName = "cohortGenerationTable-"
)
)
),

shiny::tabPanel(
Expand All @@ -148,20 +155,20 @@ cohortGeneratorViewer <- function(id) {

shiny::uiOutput(ns("inputsText")),

shinydashboard::box(
collapsible = T,
collapsed = F,
width = '100%',
title = shiny::span( shiny::icon("file-arrow-down"),'Download Data'),
#solidHeader = TRUE,

shiny::downloadButton(
ns('downloadAttritionTable'),
label = "Download",
icon = shiny::icon("download")
)
),

# shinydashboard::box(
# collapsible = T,
# collapsed = F,
# width = '100%',
# title = shiny::span( shiny::icon("file-arrow-down"),'Download Data'),
# #solidHeader = TRUE,
#
# shiny::downloadButton(
# ns('downloadAttritionTable'),
# label = "Download",
# icon = shiny::icon("download")
# )
# ),
#


shinydashboard::box(
Expand All @@ -173,7 +180,8 @@ cohortGeneratorViewer <- function(id) {
# shiny::uiOutput(ns("selectColsCohortAttrition")
# ),

resultTableViewer(ns('attritionTable'))
resultTableViewer(ns('attritionTable'),
downloadedFileName = "cohortAttritionTable-")
),

shinydashboard::box(
Expand Down
63 changes: 48 additions & 15 deletions R/components-data-viewer.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@
#' @family {Utils}
#' @return shiny module UI
#' @family {Utils}

filteredDownloadButton <- function(tableId, label = "Download (Filtered)", filename = "filteredData.csv", icon = shiny::icon("download")) {
tags$div(class = "col-sm-3",
htmltools::tags$button(
class = "btn btn-default",
tags$i(class = "fas fa-download", role = "presentation", "aria-label" = "download icon"),
label,
onclick = sprintf("Reactable.downloadDataCSV('%s', '%s')", tableId, filename)
)
)
}

resultTableViewer <- function(
id = "result-table",
downloadedFileName = NULL,
Expand All @@ -37,32 +49,41 @@ resultTableViewer <- function(
icon = shiny::icon("download")
)
),

# shiny::column(
# width = 3,
# shiny::downloadButton(
# ns('downloadDataFiltered'),
# label = "Download (Filtered)",
# icon = shiny::icon("download"),
# onClick = "Shiny.setInputValue('table_state:to_csv',
# Reactable.getState('resultData').sortedData)"
# )
# )

shiny::column(
width = 3,
shiny::actionButton(
ns('downloadDataFiltered'),
label = "Download (Filtered)",
icon = shiny::icon("download"),
onclick = paste0(
"Reactable.downloadDataCSV('",
ns('resultData'),
"', 'result-data-filtered-",
downloadedFileName,
Sys.Date(),
".csv')"
htmltools::browsable(
htmltools::tagList(
filteredDownloadButton("resultDataFiltered", "Download (Filtered)",
filename = paste('result-data-filtered-', downloadedFileName, Sys.Date(), '.csv', sep = ''),
)
)
)
)
),

shiny::fluidRow(
shinycssloaders::withSpinner(
reactable::reactableOutput(
outputId = ns("resultData"),
width = "100%")
width = "100%"
)
)
)
)
)
))
)
)
}


Expand Down Expand Up @@ -349,6 +370,8 @@ fuzzySearch<- reactable::JS('function(rows, columnIds, filterValue) {
});
}')



output$resultData <- reactable::renderReactable({
if (is.null(input$dataCols)) {
data = newdf()
Expand Down Expand Up @@ -388,14 +411,24 @@ fuzzySearch<- reactable::JS('function(rows, columnIds, filterValue) {
rowStyle = list(
height = height
),
elementId = elementIdName()
elementId = 'resultDataFiltered'
#, experimental
#theme = ohdsiReactableTheme
)
# )
# )
})

output$downloadDataFiltered <- shiny::downloadHandler(
filename = function() {
paste("result-data-filtered-", Sys.Date(), ".csv", sep = "")
},
content = function(file) {
data <- input$table_state
write.csv(data, file)
}
)


# download full data button
output$downloadDataFull <- shiny::downloadHandler(
Expand Down

0 comments on commit b5bb043

Please sign in to comment.