【问题标题】:Shiny - Scrollable panel with fixed heightShiny - 具有固定高度的可滚动面板
【发布时间】: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)

【问题讨论】:

    标签: css r shiny


    【解决方案1】:

    一种选择是使用 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改成Height:100%
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-06-21
    • 1970-01-01
    • 2011-11-20
    • 2011-07-30
    • 2011-04-24
    • 2019-05-29
    • 1970-01-01
    相关资源
    最近更新 更多