ropensci/iheatmapr

renderIheatmap breaks when used with shiny::req

daattali opened this issue · 3 comments

Any shiny output should be able to "cancel" the output if a shiny::req() fails. It seems that renderIheatmap() results in an error when a req() fails:

error in evaluating the argument 'p' in selecting a method for function 'to_widget':

This is problematic because it means that shiny apps can't conditionally show a heatmap only when the required inputs are correct.

Example:

library(shiny)

ui <- fluidPage(
  numericInput("num", "num", 5),
  iheatmapr::iheatmaprOutput("heatmap")
)

server <- function(input, output, session) {
  output$heatmap <- iheatmapr::renderIheatmap({
    req(input$num > 3)
    iheatmapr::iheatmap(matrix(rnorm(input$num * 5), nrow = input$num))
  })
}

shinyApp(ui, server)

(If you change the number to be <= 3 you'll get an error)

Is there still no solution for this problem?

This (and other shiny issues raised by Dean) are on my to-do list but I've got a bunch of other projects that are higher priority, so it may take a while to get an 0.8 release out that fixes it. Any help (even if it's just pointing to docs on how to handle things properly) is likely to speed this up

I've made a solution in the link branch (towards-0.8) that works for a reason I don't understand. Simply checking the class of the object before converting to a widget means that req works, at least in this example. Feel free to test if you need this feature