[英]How can I plot a heatmap with the heatmaply package in Shiny?
我正在嘗試使用熱圖 package 以 plot 熱圖並且效果很好。
另一方面,當我嘗試在 Shiny 中執行相同的 plot 時,它不會出現在界面中(當我單擊“運行應用程序”時)。 但是,當我關閉 window 時,plot 突然出現在 R 查看器中。 熱圖 package 是否可能不適用於 Shiny?
這是我的代碼,當我在 R 中使用 plot 時。
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 中使用它。
提前致謝,
問候
您可以使用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)
還有一個可能感興趣的 package shinyHeatmaply 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.