R Shiny Renderimage() Does Not Recognize Object 'input'
Why does renderImage() not recognize input in the code sample below: library(d3heatmap) library(shiny) library(ggplot2) ui <- fluidPage( h1('A heatmap demo'),
Solution 1:
d3heatmap()
produce the htmlwidgets
class object. We can use saveWidget()
function from the htmlwidgets
package to save plot.
library(d3heatmap)
library(shiny)
library(htmlwidgets)
ui <- fluidPage(
h1("A heatmap demo"),
selectInput("palette", "Palette", c("YlOrRd", "RdYlBu", "Greens", "Blues")),
checkboxInput("cluster", "Apply clustering"),
downloadButton('download', 'Download Heatmap'),
d3heatmapOutput("heatmap")
)
server <- function(input, output, session) {
plot <- reactive({
d3heatmap(
scale(mtcars),
colors = input$palette,
dendrogram = if (input$cluster) "both" else "none"
)
})
output$heatmap <- renderD3heatmap({
plot()
})
output$download <- downloadHandler(
filename = function() {
paste0("d3heatmap-", tolower(input$palette), ".html")
},
content = function(file) {
saveWidget(plot(), file)
}
)
}
shinyApp(ui = ui, server = server)
If you need save a plot as png see this discussion: https://github.com/ramnathv/htmlwidgets/issues/95. In short: now htmlwidgets
does not support export plots as png or svg. You can see exportwidget and webshot packages as workground.
Post a Comment for "R Shiny Renderimage() Does Not Recognize Object 'input'"