【问题标题】:How can I plot a heatmap with the heatmaply package in Shiny?如何使用 Shiny 中的 heatmaply 包绘制热图?
【发布时间】:2021-05-13 11:04:52
【问题描述】:

我正在尝试使用 heatmaply 包来绘制热图并且效果很好。

另一方面,当我尝试在 Shiny 中执行相同的绘图时,它不会出现在界面中(当我单击“运行应用程序”时)。然而,当我突然关闭窗口时,情节出现在 R 查看器中。 heatmaply 包是否可能不适用于 Shiny?

这是我的代码,当我在 R 中绘制它时。

library(heatmaply)
x  <- as.matrix(datasets::mtcars)
rc <- colorspace::rainbow_hcl(nrow(x))

heatmaply(
  x[, -c(8, 9)],
  col_side_colors = rc[1:9],
  showticklabels=FALSE,
  Rowv = TRUE,
  Colv = FALSE
)

这是我在 Shiny 中的代码。

library(shiny)
library(heatmaply)

ui <- fluidPage(

    # Application title
    titlePanel("Heatmap"),

    sidebarLayout(
        sidebarPanel(
            
        ),

        # Show a plot of the generated distribution
        mainPanel(
           plotOutput("distPlot")
        )
    )
)
x  <- as.matrix(datasets::mtcars)
rc <- colorspace::rainbow_hcl(nrow(x))

server <- function(input, output) {

    output$distPlot <- renderPlot({
        heatmaply(
          x[, -c(8, 9)],
          col_side_colors = rc[1:9],
          showticklabels=FALSE,
          Rowv = TRUE,
          Colv = FALSE
        )

     })
}

# Run the application 
shinyApp(ui = ui, server = server) 

我尝试了另一个包来制作交互式热图,但它是唯一一个拥有我想要的东西的包,因此我需要在这里询问是否有人知道如何在 Shiny 中使用它。

提前致谢,

问候

【问题讨论】:

    标签: r shiny heatmap heatmaply


    【解决方案1】:

    您可以使用plotlyOutputrenderPlotly

    library(shiny)
    library(heatmaply)
    library(plotly)
    
    ui <- fluidPage(
      
      # Application title
      titlePanel("Heatmap"),
      
      sidebarLayout(
        sidebarPanel(
          
        ),
        
        # Show a plot of the generated distribution
        mainPanel(
          plotlyOutput("distPlot")
        )
      )
    )
    x  <- as.matrix(datasets::mtcars)
    rc <- colorspace::rainbow_hcl(nrow(x))
    
    server <- function(input, output) {
      
      output$distPlot <- renderPlotly({
        heatmaply(
          x[, -c(8, 9)],
          col_side_colors = rc[1:9],
          showticklabels=FALSE,
          Rowv = TRUE,
          Colv = FALSE
        )
        
      })
    }
    
    # Run the application 
    shinyApp(ui = ui, server = server) 
    

    还有一个可能感兴趣的包shinyHeatmaply

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-14
      • 2019-10-21
      • 1970-01-01
      • 2016-01-21
      相关资源
      最近更新 更多