首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >d3heatmapOutput()在R中的变化高度

d3heatmapOutput()在R中的变化高度
EN

Stack Overflow用户
提问于 2016-05-18 12:44:06
回答 1查看 443关注 0票数 3

我正在使用R的d3heatmap库:https://cran.r-project.org/web/packages/d3heatmap/d3heatmap.pdf构建一个热图

我希望能够允许用户(通过UI)自由地调整d3heatmapOutput()函数中的d3heatmapOutput()参数。

比较以下两个代码片段(只需将它们直接复制/粘贴到R中),其中唯一的区别是height =参数在d3heatmapOutput()中的值

代码语言:javascript
复制
library(d3heatmap)
library(shiny)
ui <- fluidPage(
  h1("A heatmap demo"),
  selectInput("palette", "Palette", c("YlOrRd", "RdYlBu", "Greens", "Blues")),
  checkboxInput("cluster", "Apply clustering"),
  d3heatmapOutput("heatmap", height = "400px")
  )
server <- function(input, output, session) {
  output$heatmap <- renderD3heatmap({
    d3heatmap(
      scale(mtcars),
      colors = input$palette,
      dendrogram = if (input$cluster) "both" else "none"
) })
    }
    shinyApp(ui, server)

VS.

代码语言:javascript
复制
library(d3heatmap)
library(shiny)
ui <- fluidPage(
  h1("A heatmap demo"),
  selectInput("palette", "Palette", c("YlOrRd", "RdYlBu", "Greens", "Blues")),
  checkboxInput("cluster", "Apply clustering"),
  d3heatmapOutput("heatmap", height = "1000px")
  )
server <- function(input, output, session) {
  output$heatmap <- renderD3heatmap({
    d3heatmap(
      scale(mtcars),
      colors = input$palette,
      dendrogram = if (input$cluster) "both" else "none"
) })
    }
    shinyApp(ui, server)

我想让用户自己选择height =的这个值。但是,由于"400px"是一个非数值参数,所以UI工具(如numericInput() )无法工作。同样,selectInput()也不起作用,例如:

代码语言:javascript
复制
selectInput("foo", "Bar:", c("400px", "700px", "1000px"))

在哪里d3heatmapOutput("heatmap", height = "foo")。不幸的是,这两个选项都不起作用,这让我怀疑我是否忽略了一个更简单、更优雅的选项。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-05-18 14:41:11

在本例中,您可以使用滑块控制绘图的高度。其思想是在服务器端呈现映射,并使用paste0函数设置所需的像素大小。

代码语言:javascript
复制
library(d3heatmap)
library(shiny)
ui <- fluidPage(
  h1("A heatmap demo"),


  sliderInput("pixels", "size", value = 400, min = 100, max = 1000),

  selectInput("palette", "Palette", c("YlOrRd", "RdYlBu", "Greens", "Blues")),
  checkboxInput("cluster", "Apply clustering"),
  uiOutput("dynamic")
)
server <- function(input, output, session) {
  output$heatmap <- renderD3heatmap({
    d3heatmap(
      scale(mtcars),
      colors = input$palette,
      dendrogram = if (input$cluster) "both" else "none"
    ) })

  output$dynamic <- renderUI({

    d3heatmapOutput("heatmap", height = paste0(input$pixels, "px"))
  })

}
shinyApp(ui, server)
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37300026

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档