在Shiny中使用gridArrange
时,我很难增加地块的大小。我列举了一个问题的例子。我希望这些图填充可用空间,该空间要大得多。当我将浏览器窗口放大到全屏时,图之间的间隙会增加,但是图的大小不会改变。我尝试添加widths
和heights
参数,但随后我不断收到错误消息:only 'grobs' allowed in "gList"
。此外,当不在响应式上下文中运行时,此方法也很好。
这是我用于渲染图的代码片段:
observeEvent(input$enter_symb,{
req(length(input$enter_symb) > 0)
lista_g <- list()
output$bar_out <- renderPlot({
for (i in unique(input$enter_symb)){
a <- GLAST_RT_TPM_app[Symbol %in% i]
a$ENSEMBL <- NULL
a <- melt(a, id.vars = colnames(a)[1])
a$IP_or_S1 <- ""
a$IP_or_S1[a$variable %like% "S1"] <- "Total Tissue"
a$IP_or_S1[a$variable %like% "IP"] <- "Ribo-Tag IP"
a$region <- ""
a$region[a$variable %like% "cerebellum"] <- "Cerebellum"
a$region[a$variable %like% "cerebrum"] <- "Cerebrum"
tutul <- unique(a$Symbol)
lista_g[[i]] <- a
}
ploty <- lapply(lista_g, plot_universal)
do.call(grid.arrange, c(ploty, ncol=3))
})
})
我努力了几个小时,所以欢迎任何提示:)
更新:这是完整的代码:
library(shiny)
shinyUI(tagList(
fluidPage(
title = "test",
absolutePanel(
bottom = 400,
right = 30,
width = 380,
draggable = TRUE,
wellPanel(
actionButton("go", "Go!")
),
# end of well panel
style = "opacity: 0.70"
),
# end of absolute panel
imageOutput(outputId = "bar_out")
)
))
library(shiny)
library(data.table)
library(ggplot2)
library(dplyr)
library(DT)
data <- data.frame(replicate(3,sample(0:30,6,rep=TRUE)))
plot_universal <- function(x){
g <- ggplot(data=x, aes(y=value, x=variable)) +
geom_bar(stat = "identity", position=position_dodge(width = 0.3), width = 0.6) +
scale_fill_manual(guide = FALSE, values=alpha(c('#e89900',"#69ff65",'#e89900' , "#69ff65"), 0.8))+
# geom_text(aes(label = round(value, digits = 0)), vjust = -1, size = 4) +
labs(y = '',
x = '') +
# scale_colour_manual(name = NULL, values = c("black", "black"), labels = c('c2','c1'))+
# guides(color = guide_legend(override.aes = list(shape = 15, size = 10))) +
theme(title = element_text(size = 16, face = "plain"),
axis.title = element_text(size = 22),
text = element_text(size = 12),
axis.text.x = element_text(size = 16, face = "plain"),
axis.text.y = element_text(size = 18, face = "plain"),
legend.title.align = 0.5,
strip.text.x = element_text(size = 20, face = "plain"),
legend.position = "top",
legend.direction = "horizontal",
aspect.ratio = 1.5) +
ggtitle(unique(x[[1]]))
return(g)
}
server <- function(input, output, session) {
choose_rows <- c(1,2,3,4,5,6)
observeEvent(input$go,{
lista_g <- list()
output$bar_out <- renderPlot({
for (i in unique(choose_rows)){
a <- data[choose_rows,]
a$ENSEMBL <- NULL
a <- melt(a, id.vars = colnames(a)[1])
lista_g[[i]] <- a
}
ploty <- lapply(lista_g, plot_universal)
do.call(grid.arrange, c(ploty, ncol=3, nrow=2))
})
})
session$onSessionEnded(function(){
stopApp()
})
}