我正在尝试使用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中使用它。
提前谢谢你,
问候
发布于 2021-05-13 20:30:29
您可以使用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。
https://stackoverflow.com/questions/67518151
复制相似问题