gpt4 book ai didi

css - Shiny - 具有固定高度的可滚动面板

转载 作者:太空宇宙 更新时间:2023-11-03 21:13:32 25 4
gpt4 key购买 nike

我正在按照一个 Shiny 的示例在 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)

最佳答案

一种选择是使用 CSS。将所有内容按照您想要的方式放置可能需要一些摆弄。这是一个简单的例子:

require(shiny)

ui <- shinyUI(fluidPage(
#fixedRow(uiOutput('plots'), height="100px")
tags$style(HTML("
#plots {
height:100px;
overflow-y:scroll
}
")),
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)

关于css - Shiny - 具有固定高度的可滚动面板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44164149/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com