shiny icon indicating copy to clipboard operation
shiny copied to clipboard

Unable to call shiny::renderTable via do.call since Shiny version 1.7.0

Open chwpearse opened this issue 3 years ago • 1 comments

System details

Windows 10

Browser Version: NA

Output of sessionInfo():

R version 4.1.1 (2021-08-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19043)

Matrix products: default

locale:
[1] LC_COLLATE=English_United Kingdom.1252  LC_CTYPE=English_United Kingdom.1252    LC_MONETARY=English_United Kingdom.1252
[4] LC_NUMERIC=C                            LC_TIME=English_United Kingdom.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] reprex_2.0.1    forcats_0.5.1   stringr_1.4.0   dplyr_1.0.8     purrr_0.3.4     readr_2.1.2     tidyr_1.2.0     tibble_3.1.6    ggplot2_3.3.5  
[10] tidyverse_1.3.1 R6_2.5.1        shiny_1.7.1     devtools_2.4.3  usethis_2.1.5  

loaded via a namespace (and not attached):
 [1] fs_1.5.2          lubridate_1.8.0   httr_1.4.2        rprojroot_2.0.2   R.cache_0.15.0    tools_4.1.1       backports_1.4.1   utf8_1.2.2       
 [9] DBI_1.1.2         colorspace_2.0-2  withr_2.4.3       tidyselect_1.1.1  prettyunits_1.1.1 processx_3.5.2    compiler_4.1.1    cli_3.2.0        
[17] rvest_1.0.2       xml2_1.3.3        desc_1.4.0        scales_1.1.1      callr_3.7.0       digest_0.6.29     rmarkdown_2.11    R.utils_2.11.0   
[25] pkgconfig_2.0.3   htmltools_0.5.2   sessioninfo_1.2.2 styler_1.6.2      dbplyr_2.1.1      fastmap_1.1.0     highr_0.9         rlang_1.0.1      
[33] readxl_1.3.1      rstudioapi_0.13   generics_0.1.2    jsonlite_1.7.3    R.oo_1.24.0       magrittr_2.0.2    Rcpp_1.0.8        munsell_0.5.0    
[41] fansi_1.0.2       clipr_0.7.1       RODBC_1.3-19      lifecycle_1.0.1   R.methodsS3_1.8.1 yaml_2.2.2        stringi_1.7.6     brio_1.1.3       
[49] pkgbuild_1.3.1    grid_4.1.1        promises_1.2.0.1  crayon_1.5.0      haven_2.4.3       hms_1.1.1         knitr_1.37        ps_1.6.0         
[57] pillar_1.7.0      pkgload_1.2.4     glue_1.6.1        evaluate_0.14     remotes_2.4.2     modelr_0.1.8      vctrs_0.3.8       tzdb_0.2.0       
[65] httpuv_1.6.5      testthat_3.1.2    cellranger_1.1.0  gtable_0.3.0      assertthat_0.2.1  cachem_1.0.6      xfun_0.29         mime_0.12        
[73] xtable_1.8-4      broom_0.7.12      later_1.3.0       memoise_2.0.1     ellipsis_0.3.2   

Example application or steps to reproduce the problem

Running code with Shiny version 1.7.1

library(devtools)
#> Warning: package 'devtools' was built under R version 4.1.2
#> Loading required package: usethis
#> Warning: package 'usethis' was built under R version 4.1.2
install.packages('shiny')
#> Installing package into 'C:/Users/chwpe/Documents/R/win-library/4.1'
#> (as 'lib' is unspecified)
#> package 'shiny' successfully unpacked and MD5 sums checked
#> 
#> The downloaded binary packages are in
#>  C:\Users\chwpe\AppData\Local\Temp\RtmpemTuse\downloaded_packages
library(shiny)
#> Warning: package 'shiny' was built under R version 4.1.2
library(R6)

args <- list(striped = TRUE)
do.call(shiny::renderTable, list(data.frame(a = 1:3), args))
#> Error in exprToQuo(expr, env, quoted = TRUE): Don't know how to convert 'data.frame' to a function; a quosure or quoted expression was expected

table_class <- R6Class(
  'table_class',
  public = list(
    initialize = function(data, render_args){
      private$data = data
      private$render_args = list(render_args)
    },
    render = function(...){
      
      call_args <- append(private$render_args, list(...))
      call_args[['expr']] <- private$data
      do.call(shiny::renderTable, call_args)
    }
  ),
  private = list(
    data = NULL,
    render_args = NULL
  )
)

table_obj <- table_class$new(data = data.frame(a = 1:3), render_args = list(striped = TRUE))
table_obj$render()
#> Error in exprToQuo(expr, env, quoted = TRUE): Don't know how to convert 'data.frame' to a function; a quosure or quoted expression was expected

Created on 2022-02-23 by the reprex package (v2.0.1)

Running code with Shiny version 1.6.0

library(devtools)
#> Warning: package 'devtools' was built under R version 4.1.2
#> Loading required package: usethis
#> Warning: package 'usethis' was built under R version 4.1.2
install_version("shiny", version = "1.6.0", repos = "http://cran.us.r-project.org")
#> Downloading package from url: http://cran.us.r-project.org/src/contrib/Archive/shiny/shiny_1.6.0.tar.gz
#> jsonlite (1.7.3 -> 1.8.0) [CRAN]
#> Installing 1 packages: jsonlite
#> Installing package into 'C:/Users/chwpe/Documents/R/win-library/4.1'
#> (as 'lib' is unspecified)
#> Warning in i.p(...): installation of package 'jsonlite' had non-zero exit status
#> Installing package into 'C:/Users/chwpe/Documents/R/win-library/4.1'
#> (as 'lib' is unspecified)
library(shiny)
library(R6)

args <- list(striped = TRUE)
do.call(shiny::renderTable, list(data.frame(a = 1:3), args))
#> <shiny.render.function> 
table_class <- R6Class(
  'table_class',
  public = list(
    initialize = function(data, render_args){
      private$data = data
      private$render_args = list(render_args)
    },
    render = function(...){
      
      call_args <- append(private$render_args, list(...))
      call_args[['expr']] <- private$data
      do.call(shiny::renderTable, call_args)
    }
  ),
  private = list(
    data = NULL,
    render_args = NULL
  )
)

table_obj <- table_class$new(data = data.frame(a = 1:3), render_args = list(striped = TRUE))
table_obj$render()
#> <shiny.render.function> 

Created on 2022-02-23 by the reprex package (v2.0.1)

Describe the problem in detail

Calling shiny::renderTable and some other shiny render functions via do.call worked prior to version 1.7.0. I think the code added to support quo (https://github.com/rstudio/shiny/pull/3472) caused this change in behavior.

chwpearse avatar Feb 23 '22 02:02 chwpearse

Apologies for the lack of response here. If it helps at all, you can now do:

x <- list(data.frame(a = 1:3), args)
shiny::renderTable(!!!x)

cpsievert avatar Jul 18 '25 21:07 cpsievert