【发布时间】:2017-10-25 03:19:28
【问题描述】:
我正在按照一个闪亮的例子在 uiOutput 中绘制多个图。我想要一个包含这些图的面板(正确的词?)有一个固定的高度,但允许滚动查看超出此高度的图。
我尝试将 uiOutput() 包含在具有固定高度的 fixedRow 中,但它不起作用。
我已经包含了下面的代码
require(shiny)
ui <- shinyUI(fluidPage(
#fixedRow(uiOutput('plots'), height="100px")
uiOutput('plots')
))
server <- shinyServer(function(input, output) {
plots <- lapply(1:10, function(i){
plot(runif(50),main=sprintf('Plot nr #%d',i))
p <- recordPlot()
plot.new()
p
})
n.col <- 3
output$plots <- renderUI({
col.width <- round(12/n.col) # Calculate bootstrap column width
n.row <- ceiling(length(plots)/n.col) # calculate number of rows
cnter <<- 0 # Counter variable
# Create row with columns
rows <- lapply(1:n.row,function(row.num){
cols <- lapply(1:n.col, function(i) {
cnter <<- cnter + 1
plotname <- paste("plot", cnter, sep="")
column(col.width, plotOutput(plotname, height = 280, width = 250))
})
fluidRow( do.call(tagList, cols) )
})
do.call(tagList, rows)
})
for (i in 1:length(plots)) {
local({
n <- i # Make local variable
plotname <- paste("plot", n , sep="")
output[[plotname]] <- renderPlot({
plots[[n]]
})
})
}
})
shinyApp(ui=ui,server=server)
【问题讨论】: