如何解决如何使用 Shiny 中的 heatmaply 包绘制热图?
我正在尝试使用 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[,Colv = FALSE
)
})
}
# Run the application
shinyApp(ui = ui,server = server)
我尝试了另一个软件包来制作交互式热图,但它是唯一一个具有我想要的功能的软件包,因此我需要在这里询问是否有人知道如何在 Shiny 中使用它。
提前致谢,
问候
解决方法
您可以使用 plotlyOutput
和 renderPlotly
:
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 可能很有趣。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。