Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
更改R中d3heatmapOutput()的高度_R_Shiny_D3heatmap - Fatal编程技术网

更改R中d3heatmapOutput()的高度

更改R中d3heatmapOutput()的高度,r,shiny,d3heatmap,R,Shiny,D3heatmap,我正在使用D3R的热图库构建热图: 我希望能够允许用户(通过UI)自由调整d3heatmapOutput()函数中的height=参数 比较以下两个代码片段(只需将它们直接复制/粘贴到R Studio中),它们之间的唯一区别是d3heatmapOutput()中height=参数的值: 其中d3heatmap输出(“heatmap”,height=“foo”)。不幸的是,这两个选项都不起作用,这让我怀疑我是否忽略了一个更简单、更优雅的选项。在本例中,您可以使用滑块控制绘图的高度。其思想是在服务器

我正在使用D3R的热图库构建热图:

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

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


其中
d3heatmap输出(“heatmap”,height=“foo”)
。不幸的是,这两个选项都不起作用,这让我怀疑我是否忽略了一个更简单、更优雅的选项。

在本例中,您可以使用滑块控制绘图的高度。其思想是在服务器端渲染地图,并使用
paste0
功能设置所需的像素大小

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)
库(D3热图)
图书馆(闪亮)
用户界面
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)
selectInput("foo", "Bar:", c("400px", "700px", "1000px"))
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)