【发布时间】:2020-02-20 10:00:40
【问题描述】:
我是闪亮的新手,正在尝试制作闪亮的应用程序。我需要根据用户输入的数字使用pheatmap 绘制热图。数据太大,但这里有一个可重现的数据:
a<-structure(list(gene_name = c("NAT2", "ACADS", "ACAT1", "ADA",
"ADRB2", "ADRB3"), tree = c(1L, 2L, 3L, 3L, 4L, 4L)), row.names = c(NA,
6L), class = "data.frame")
b<-structure(list(Phaeodactylum_tricornutum = c(0, 1, 1, 1, 0, 0
), Coccomyxa_subellipsoidea = c(0, 1, 1, 1, 0, 0), Acanthamoeba_castellanii = c(1,
1, 1, 1, 0, 0), Fonticula_alba = c(0, 1, 1, 1, 0, 0), Rhizophagus_irregularis = c(0,
1, 1, 1, 0, 0), Sphaeroforma_arctica = c(0, 1, 1, 1, 0, 0), Capsaspora_owczarzaki = c(0,
1, 1, 1, 0, 0), Cryptosporidium_parvum = c(0, 0, 0, 0, 0, 0),
Enterobacter_cloacae = c(1, 1, 1, 1, 0, 0), gene_name = c("NAT2",
"ACADS", "ACAT1", "ADA", "ADRB2", "ADRB3"), human_np = c("NP_000006.2",
"NP_000008.1", "NP_000010.1", "NP_000013.2", "NP_000015.1",
"NP_000016.1")), row.names = c(NA, 6L), class = "data.frame")
这是闪亮的代码:
library(shiny)
library(DT)
library(pheatmap)
library(dplyr)
# Define UI ----
ui <- fluidPage(
titlePanel("title panel"),
sidebarLayout(
sidebarPanel("sidebar panel"
),
mainPanel("main panel",
numericInput(inputId = "cl",
h3("Cluster number"),
value = 1, min = 1, max = 2),
plotOutput("cls_num"),
)
)
)
# Define server logic
server <- function(input, output) {
clinput<-reactive({
b[which(a$tree == input$cl),1:9]
})
output$cls_num<-renderPlot({
clinput()%>%
pheatmap(cluster_rows = FALSE, cluster_cols = FALSE)
})
}
# Run the app ----
shinyApp(ui = ui, server = server)
问题是,当我运行应用程序时,它只在我调整窗口大小时显示绘图,而在我更改输入后,我需要再次调整窗口大小才能看到热图。这在 rstudio 和浏览器中都会发生。
提前致谢。
【问题讨论】:
-
您正在使用 rstudio?关闭你的绘图设备,dev.off() 我意识到这一点,因为我总是在终端上工作
-
是的,我正在使用 rstudio 并关闭绘图设备!非常感谢。
-
仅供参考:我提交了一个问题here。