【发布时间】:2015-12-27 06:49:47
【问题描述】:
为什么renderImage()无法识别下面代码示例中的input:
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)
这是我的错误:
Error in match.arg(dendrogram) : object 'input' not found
当我删除dendrogram = if (input$cluster) "both" else "none" 行时,我再次收到以下关于input 的错误:
Error in toPaletteFunc(pal) : object 'input' not found
没有找到对象input 似乎有点违反直觉,因为我已经在楼上明确定义了它:server <- function(input, output, session)。
我已经检查过现有的 Stack Overflow 帖子,这些帖子会生成类似的错误消息(例如,R Shiny error: object input not found)。
上面的代码示例的灵感来自:https://cran.r-project.org/web/packages/d3heatmap/d3heatmap.pdf
【问题讨论】:
-
renderImage与imageOuput一起使用。downloadButton与downloadHandler。阅读文档。 -
没有
downloadButton,此代码有效。您应该为downloadButton编写一个处理程序。
标签: r shiny htmlwidgets