【发布时间】:2018-11-27 14:10:38
【问题描述】:
有没有办法增加shiny 中的绘图窗口大小,具体取决于ggplot 图形中使用的构面数量 - 可能使用垂直滚动。
例如,使用下面的示例,当输入为"A" 时,有三个方面,图看起来不错。选择选项"B" "B"时,绘图的数量增加,但绘图窗口保持相同的大小,从而导致绘图太小。
是否有策略使所有面板高度保持相同,而与输入无关?谢谢。
library(ggplot2)
library(shiny)
mtcars$cyl = sample(letters[1:5], 32, TRUE)
ui <- fluidPage(
navbarPage(title="title",
tabPanel("One",
column(3,
wellPanel( selectInput('name', 'NAME', c("A", "B")))),
column(9, plotOutput('plot1')))
))
server <- function(input, output) {
X = reactive({input$name == "A"})
output$plot1 <- renderPlot({
if(X()){
p1 = ggplot(mtcars, aes(mpg, wt)) + facet_grid( . ~ gear )
}else{
p1 = ggplot(mtcars, aes(mpg, wt)) + facet_grid( cyl ~ gear )
}
return(p1)})
}
shinyApp(ui, server)
【问题讨论】: