Skip to content

Commit

Permalink
Merge pull request #66 from GSK-Biostatistics/page_plan
Browse files Browse the repository at this point in the history
Page plan
  • Loading branch information
bzkrouse authored Mar 12, 2024
2 parents 5633d0e + 6089536 commit a87a3e8
Show file tree
Hide file tree
Showing 24 changed files with 885 additions and 271 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Imports:
gt,
rlang,
sortable,
bslib,
bslib (>= 0.6.0),
shinyWidgets,
rio,
shinycssloaders,
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ importFrom(shinyjs,toggleState)
importFrom(shinyjs,useShinyjs)
importFrom(stats,setNames)
importFrom(utils,getFromNamespace)
importFrom(utils,zip)
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# tfrmtbuilder development version

* New features:
- Add support for `page_plan`
- Add support for additional output formats

* Bug fixes:
- Fix navbar link underline css conflict to support bslib >= 0.6.0

# tfrmtbuilder 0.0.5

- Improve robustness of how `tfrmt` internal functions are called.
Expand Down
2 changes: 0 additions & 2 deletions R/mod_datamapping_inputs.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ datamapping_inputs_server <- function(id, data, settings_in, reset, multiple, re
# hide add/drop inputs if multiple = FALSE
observe({
toggle("multiples", condition = multiple==TRUE)
toggle("multiples", condition = multiple==TRUE)

})

# starts at zero, 1 for initial state, then increments for each edit
Expand Down
59 changes: 15 additions & 44 deletions R/mod_export.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,16 @@ export_ui <- function(id){
div(style = "height: 650px;",
h3("Table", class = "heading_style",
span(class = "btn-export", style = "display: flex; gap: 5px;",
div(downloadButton(ns("tbl_save_html"), label = "HTML", icon = icon("download"))),
div(downloadButton(ns("tbl_save_png"), label = "PNG", icon = icon("download")))),
lapply(c("html","png","rtf","docx","pdf","tex"), function(ext){
mod_export_table_ui(ns(ext), ext=ext)
})
)
),
div(style = "height: 550px; overflow-y:auto; ",
shinycssloaders::withSpinner(
color = getOption("spinner.color", default = "#254988"),
type = 4,
gt_output(ns("tbl"))
)
table_inner_ui(ns("tbl_view"))
)
)
)
)
)
)
)
Expand All @@ -52,7 +50,7 @@ export_ui <- function(id){
#' @param mode mock mode w/ no data, w/ data, reporting
#'
#' @noRd
export_server <- function(id, data, tfrmt_app_out, mode){
export_server <- function(id, data, tfrmt_app_out, settings){

moduleServer(
id,
Expand All @@ -63,24 +61,13 @@ export_server <- function(id, data, tfrmt_app_out, mode){
tfrmt_app_out() %>% tfrmt_to_json()
})

tbl_out <- reactive({
req(tfrmt_app_out())
mode <- isolate(mode())

if (mode=="reporting"){
tfrmt_app_out() %>% print_to_gt(.data = data())

} else if (mode=="mock_no_data"){
tfrmt_app_out() %>% print_mock_gt()

} else {
tfrmt_app_out() %>% print_mock_gt(.data = data())
}
auto_tbl <- reactiveVal(0)
observeEvent(tfrmt_app_out(), {
auto_tbl(auto_tbl()+1)
})

output$tbl <- render_gt({
tbl_out()
})
tbl_out <- table_inner_server("tbl_view", data = data, tfrmt_app_out = tfrmt_app_out, settings = settings, auto_tbl = auto_tbl)


output$json_save <- downloadHandler(
filename = function() {
Expand All @@ -91,24 +78,8 @@ export_server <- function(id, data, tfrmt_app_out, mode){
}
)

output$tbl_save_html <- downloadHandler(
filename = function() {
paste('tfrmt.html', sep='')
},
content = function(con) {
gtobj <- tbl_out()
gtsave(gtobj, con)
}
)

output$tbl_save_png <- downloadHandler(
filename = function() {
paste('tfrmt.png', sep='')
},
content = function(con) {
gtobj <- tbl_out()
gtsave(gtobj, con)
}
)
lapply(c("html","png","rtf","docx","pdf","tex"), function(ext){
mod_export_table_server(ext, tbl=tbl_out, ext=ext)
})
})
}
58 changes: 58 additions & 0 deletions R/mod_export_table.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@

# module for table download button for given output type

mod_export_table_ui <- function(id, ext){

ns <- NS(id)

tagList(
div(downloadButton(ns("tbl_save"), label = toupper(ext), icon = icon("download")))
)
}

mod_export_table_server <- function(id, tbl, ext){

moduleServer(
id,
function(input, output, session) {


output$tbl_save <- downloadHandler(
filename = function() {
if (inherits(tbl(), "gt_group") && tolower(ext) %in% c("png", "pdf")){
paste0('tfrmt_', tolower(ext), '.zip')
} else {
paste0('tfrmt.', tolower(ext))
}
},
content = function(con) {

if (inherits(tbl(), "gt_group") && tolower(ext) %in% c("png", "pdf")){
temp_dir <- tempdir()
dir.create(temp_dir)

n_tbls <- nrow(tbl()$gt_tbls)
walk(1:n_tbls, function(x){
tbl() %>% grp_pull(x) %>% gtsave(filename = paste0("tfrmt_",x,".", tolower(ext)), path = temp_dir)
})

zip(
zipfile = con,
files = file.path(temp_dir, paste0("tfrmt_", seq_along(tbl()), ".", tolower(ext))),
flags = "-r9Xj"
)

} else{

gtobj <- tbl()
gtsave(gtobj, con)

}
}
)



}
)
}
6 changes: 4 additions & 2 deletions R/mod_filters.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ filters_ui <- function(id){
filters_server <- function(id, data, tfrmt_app, selected,
include,
null_to_default = TRUE,
add_default_opt = FALSE,
allow_create = reactive(TRUE)){

moduleServer(
Expand All @@ -50,7 +51,6 @@ filters_server <- function(id, data, tfrmt_app, selected,

})


# loop through all variables in the var shell
output$filters <- renderUI({

Expand All @@ -71,14 +71,16 @@ filters_server <- function(id, data, tfrmt_app, selected,
selected_vars <- list(column_val = selected_vars_nms)

} else{

selected_vars <- selected() %>%
keep_at(paste0(var, "_val"))
}

all_vars <- var_shell()[[var]]
ui_list[[i]] <- create_filter_select(ns, paste0(var, "_val"), data,
selected_vars, all_vars,
allow_create(), null_to_default)
allow_create(), null_to_default,
add_default_opt)

}

Expand Down
6 changes: 5 additions & 1 deletion R/mod_home.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ home_server <- function(id){
moduleServer(
id,
function(input, output, session) {

addResourcePath("www", system.file('www',
package = 'tfrmtbuilder'))

output$about <- renderUI({
HTML("
<h2 class=heading_style> Welcome to the {tfrmtbuilder} Shiny App </h2>
Expand Down Expand Up @@ -68,7 +72,7 @@ home_server <- function(id){
})

output$hex <- renderUI({
HTML(" <left> <img src=https://github.com/GSK-Biostatistics/tfrmt/blob/main/man/figures/tfrmt.png?raw=true
HTML(" <left> <img src= 'www/tfrmtbuilder_hex.png'
alt=hex width=75% > </left> ")

})
Expand Down
Loading

0 comments on commit a87a3e8

Please sign in to comment.