gpt4 book ai didi

r - 如何使用 Shiny 中的 heatmaply 包绘制热图?

转载 作者:行者123 更新时间:2023-12-02 18:45:24 25 4
gpt4 key购买 nike

我正在尝试使用 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 中使用它。

提前致谢,

问候

最佳答案

您可以使用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)

enter image description here

还有一个包shinyHeatmaply这可能会引起兴趣。

关于r - 如何使用 Shiny 中的 heatmaply 包绘制热图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67518151/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com