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

allow trace for invalid quosures #86

Merged
merged 5 commits into from
Sep 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 3 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
### Enhancements
* Updated `standard_layout` function to contain class not id for each output block.
* Added the `dim` slot to the list returned by the `plot_with_settings` module.
* Added `style` argument to `verbatim_popup_srv` to control whether the content is styled using `styler::style_text`
* Added `style` argument to `verbatim_popup_srv` to control whether the content is styled using `styler::style_text`.
* `condition` objects can now be displayed in `verbatim_popup`.

### Bug fixes
* fixed bug in `verbatim_popup_srv` where `disabled` argument didn't influence the popup button.
* Fixed bug in `verbatim_popup_srv` where `disabled` argument didn't influence the popup button.

### New features
* Added a new module - `verbatim_popup`.
Expand Down
20 changes: 13 additions & 7 deletions R/verbatim_popup.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ verbatim_popup_ui <- function(id, button_label, ...) {
#' @name verbatim_popup
#' @export
#'
#' @param verbatim_content (`character`, `expression` or `reactive(1)` holding either)
#' the content to show in the popup modal window
#' @param verbatim_content (`character`, `expression`, `condition` or `reactive(1)`
#' holding any of the above) the content to show in the popup modal window
#' @param title (`character(1)`) the title of the modal window
#' @param style (`logical(1)`) whether to style the `verbatim_content` using `styler::style_text`
#' @param style (`logical(1)`) whether to style the `verbatim_content` using `styler::style_text`.
#' If `verbatim_content` is a `condition` or `reactive` holding `condition` then this argument is ignored
#' @param disabled (`reactive(1)`) the `shiny` reactive value holding a `logical`. The popup button is disabled
#' when the flag is `TRUE` and enabled otherwise
#'
Expand Down Expand Up @@ -147,18 +148,23 @@ button_click_observer <- function(click_event, copy_button_id, copied_area_id, m
format_content <- function(verbatim_content, style = FALSE) {
shiny::reactive({
content <- if (inherits(verbatim_content, "reactive")) {
verbatim_content()
tryCatch(
verbatim_content(),
error = function(e) {
e
}
)
} else {
verbatim_content
}
shiny::validate(shiny::need(
checkmate::test_multi_class(content, classes = c("expression", "character")),
"verbatim_content should be an expression or a character"
checkmate::test_multi_class(content, classes = c("expression", "character", "condition")),
"verbatim_content should be an expression, character or condition"
))

content <- paste(as.character(content), collapse = "\n")

if (style) {
if (style && !checkmate::test_class(content, "condition")) {
content <- paste(styler::style_text(content), collapse = "\n")
}
content
Expand Down
7 changes: 4 additions & 3 deletions man/format_content.Rd

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

7 changes: 4 additions & 3 deletions man/verbatim_popup.Rd

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

13 changes: 12 additions & 1 deletion tests/testthat/test-verbatim_popup.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ testthat::test_that("format_content returns a `shiny` reactive when passed a rea
testthat::expect_true(inherits(format_content(test_content), "reactive"))
})

testthat::test_that("format_content returns a reactive when passed a condition", {
test_content <- structure("Test Content", clas = "condition")
testthat::expect_true(inherits(format_content(test_content), "reactive"))
})

testthat::test_that("format_content returns a reactive when passed a reactive holding a condition", {
test_content <- shiny::reactive({
validate(need(1 > 4, "1 is less than 4"))
})
testthat::expect_true(inherits(format_content(test_content), "reactive"))
})

testthat::test_that("format_content concatenates the passed array of strings", {
test_content <- c("Test", "Content")
result <- shiny::isolate(format_content(test_content))
Expand All @@ -31,7 +43,6 @@ testthat::test_that("format_content concatenates the passed array of string insi
testthat::expect_length(result, 1)
})


testthat::test_that(
"format_content returns a reactive storing a styled string when passed
an expression, character or reactive when style = TRUE",
Expand Down