From 01dbb364c4b71f231493f118d6371a2421da83d5 Mon Sep 17 00:00:00 2001 From: Derek Burk Date: Wed, 27 Sep 2023 15:44:15 -0500 Subject: [PATCH 1/3] Fix two bugs in `ipums_view`: (1) nothing was displaying in the Viewer pane at all, and (2) the Labelled Values table was collapsed such that no rows were visible when viewed in the Viewer pane (fixes #19) --- R/viewer.R | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/R/viewer.R b/R/viewer.R index 269ae96a..1cc200f1 100644 --- a/R/viewer.R +++ b/R/viewer.R @@ -60,18 +60,6 @@ ipums_view <- function(x, out_file = NULL, launch = TRUE) { htmltools::save_html(html_page, out_file) - on.exit( - unlink(list.files(tempdir(), ".html", full.names = TRUE)), - add = TRUE, - after = FALSE - ) - - on.exit( - unlink(file.path(tempdir(), "lib"), recursive = TRUE), - add = TRUE, - after = FALSE - ) - if (launch) { if (requireNamespace("rstudioapi", quietly = TRUE)) { rstudioapi::viewer(out_file) @@ -147,11 +135,19 @@ display_ipums_var_row <- function(var_name, code_instr <- split_double_linebreaks_to_ptags(code_instr) if (nrow(val_labels) > 0) { + # The line below is a hacky solution to a problem that collapses the + # height of the value labels table such that no rows are visible when viewed + # in the RStudio Viewer pane + val_lbls_height_in_pixels <- paste0( + 200 + min(nrow(val_labels), 10) * 30, + "px" + ) value_labels <- DT::datatable( val_labels, style = "bootstrap", rownames = FALSE, - width = "100%" + width = "100%", + height = val_lbls_height_in_pixels ) } else { value_labels <- htmltools::tags$p("N/A") From 7eabc722e7fb28859044e7a9ff50866ea868864a Mon Sep 17 00:00:00 2001 From: Finn Roberts Date: Thu, 5 Oct 2023 11:21:32 -0400 Subject: [PATCH 2/3] Remove "More details" text when link is missing --- R/viewer.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/R/viewer.R b/R/viewer.R index 1cc200f1..0da6030f 100644 --- a/R/viewer.R +++ b/R/viewer.R @@ -163,7 +163,8 @@ display_ipums_var_row <- function(var_name, ), silent = TRUE ) - if (inherits(class(url)[1], "try-error")) { + + if (inherits(url, "try-error")) { link <- NULL } else { link <- htmltools::a(href = url, "More details") From 49a082668fbc78a46701af4f761da0ffe18d7d21 Mon Sep 17 00:00:00 2001 From: Finn Roberts Date: Fri, 6 Oct 2023 11:51:46 -0400 Subject: [PATCH 3/3] Fix `ipums_view()` failure when no extract notes --- R/viewer.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/viewer.R b/R/viewer.R index 0da6030f..b78e8688 100644 --- a/R/viewer.R +++ b/R/viewer.R @@ -229,7 +229,7 @@ expandable_div <- function(title, subtitle, content) { } split_double_linebreaks_to_ptags <- function(x) { - if (is.null(x)) { + if (is.null(x) || x == "") { return("") } out <- fostr_split(x, "\n\n")[[1]] @@ -237,7 +237,7 @@ split_double_linebreaks_to_ptags <- function(x) { } convert_single_linebreak_to_brtags <- function(x) { - if (is.null(x)) { + if (is.null(x) || x == "") { return(NULL) }