zeehio/condformat

async support for Shiny

Closed this issue · 2 comments

Hey,

It would be cool if this package were updated to support the recently added shiny async render functions. At the moment, renderCondformat() does not handle promises.

Here is a minimal repro:

library(shiny)
library(future)
library(promises)
library(condformat)
library(dplyr)

ui <- fluidPage(
  actionButton("execute", "Execute"),
  helpText("The synchronous table output"),
  condformatOutput("sync_table"),
  helpText("The asynchronous table output"),
  condformatOutput("async_table")
)

server <- function(input, output) {
  
  our_sync_data <- reactive({
    input$execute
    
    data.frame(type = c(rep("A", 5), rep("B", 5)),
               n = seq(1,100,10))
  })
  
  our_async_data <- reactive({
    input$execute
    
    future({
      
      data.frame(type = c(rep("A", 5), rep("B", 5)),
                 n = seq(1,100,10))
    })
  })
  
  output$sync_table <- renderCondformat({
    
    our_sync_data() %>% 
      condformat() %>% 
      rule_fill_discrete(type, expression = n <= 50,
                         colours = c("TRUE" = "yellowgreen", "FALSE" = "tomato"))
  })
  
  output$async_table <- renderCondformat({
    
    our_async_data() %...>% 
      condformat() %...>% 
      rule_fill_discrete(type, expression = n <= 50,
                         colours = c("TRUE" = "yellowgreen", "FALSE" = "tomato"))
  })
}

shinyApp(ui, server)

And here is the output of sessionInfo():

> sessionInfo()
R version 3.4.2 (2017-09-28)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS High Sierra 10.13.4

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib

locale:
[1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8

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

other attached packages:
[1] promises_1.0.1   dplyr_0.7.4      condformat_0.7.0 future_1.8.1     shiny_1.0.5 

Thank you!

Thanks for the bug report and sorry for the late reply.

The issue is now solved in the dev version of condformat. Note that the solution depends on having htmlwidgets >= 1.3 installed, currently available on github.

devtools::install_github('ramnathv/htmlwidgets')

I will leave the issue open until htmlwidgets 1.3 is released, and once that happens I will close this issue and submit condformat to CRAN.

htmlwidgets current CRAN version:

Best

Fix released on CRAN 0.8.0. (Windows and OSX packages will be built during the next ~48h)