【发布时间】:2017-04-28 11:45:57
【问题描述】:
我有一个取决于用户输入的情节。 根据输入,绘图大小会有所不同。
我可以动态控制绘图的高度吗?
我知道在 plotOutput() 我有一个高度参数,但我找不到动态更改它的方法。
可重现的例子,当你选择 A 时,情节看起来很好,但如果你选择 B,那就太高了-
library(shiny)
library(ggplot2)
df1 <- data.frame(x = 1:2000, y = rnorm(2000), type = rep(LETTERS[1:8], 250))
df2 <- data.frame(x = 1:100, y = rexp (100), type = rep(c('A','B'), 50))
ui <- shinyUI(fluidPage(title = '',
fluidRow(selectInput("table",'', choices = c('A','B'))),
fluidRow(plotOutput("my_plot", height = '1000px'))
)
)
server <- shinyServer(function(input, output) {
output$my_plot <- renderPlot({
t <- if(input$table == 'A') df1
else df2
ggplot(t) + facet_grid(type~.) +
geom_point(mapping = aes(x=x, y=y))
}
)
})
shinyApp(ui, server)
最后一件事,在真正的应用程序中,并不是我有 2 种不同的尺寸,这取决于需要改变尺寸的输入。
【问题讨论】:
标签: r plot shiny conditional