Why does renderImage()
not recognize input
in the code sample below:
library(d3heatmap)
library(shiny)
library(ggplot2)
ui <- fluidPage(
h1("A heatmap demo"),
selectInput("palette", "Palette", c("YlOrRd", "RdYlBu", "Greens", "Blues")),
checkboxInput("cluster", "Apply clustering"),
downloadButton('downloadPlot', 'Download Heatmap'),
d3heatmapOutput("heatmap")
)
server <- function(input, output, session) {
output$heatmap <- renderD3heatmap({
d3heatmap(
scale(mtcars),
colors = input$palette,
dendrogram = if (input$cluster) "both" else "none"
) })
output$downloadPlot <- renderImage(
d3heatmap(scale(mtcars), colors = input$palette, dendrogram = if (input$cluster) "both" else "none"),
env = parent.frame(),
quoted = FALSE,
deleteFile = FALSE
)
}
shinyApp(ui = ui, server = server)
This is my error:
Error in match.arg(dendrogram) : object 'input' not found
When I remove the dendrogram = if (input$cluster) "both" else "none"
line, I get the following error concerning input
again:
Error in toPaletteFunc(pal) : object 'input' not found
It seems a bit counterintuitive that the object input
isn't found, as I've explicitly defined it upstairs with: server <- function(input, output, session)
.
I've already examined existing Stack Overflow posts that generate a similar error message (e.g., R Shiny error: object input not found).
Code sample above was inspired by: https://cran.r-project.org/web/packages/d3heatmap/d3heatmap.pdf