diff --git a/NEWS.md b/NEWS.md index 93a4192e8..44095dde4 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,9 @@ # shiny (development version) +## Bug fixes and minor improvements + +* Using `renderXXX` functions in the UI will now return an error (#4189). + # shiny 1.12.1 ## New features diff --git a/R/shinywrappers.R b/R/shinywrappers.R index dca587398..40ae4a85a 100644 --- a/R/shinywrappers.R +++ b/R/shinywrappers.R @@ -328,6 +328,12 @@ useRenderFunction <- function(renderFunc, inline = FALSE) { #' @export #' @method as.tags shiny.render.function as.tags.shiny.render.function <- function(x, ..., inline = FALSE) { + # return an error when render functions are used in UI + if (is.null(getDefaultReactiveDomain())) { + stop("There is a renderXXX function in the UI, these should only be used in the server function.", + "Use the corresponding XXXOutput function in the UI instead.") + } + useRenderFunction(x, inline = inline) } diff --git a/tests/testthat/test-shinywrappers.R b/tests/testthat/test-shinywrappers.R index 4de179496..5b517c97d 100644 --- a/tests/testthat/test-shinywrappers.R +++ b/tests/testthat/test-shinywrappers.R @@ -1,3 +1,8 @@ +test_that("render functions in UI throw informative error", { + expect_error(as.tags.shiny.render.function(renderTable("table")), + "There is a renderXXX function in the UI") +}) + test_that("isTemp passes sanity checks", { t <- tempfile(fileext = ".txt") writeLines("hello", t)