2017-05-24 14 views
0

私はuiOutputに複数のプロットをプロットするための光沢のある例に従っています。これらのプロットを含むパネル(正しい単語?)には固定された高さがありますが、この高さを超えるプロットをスクロールして見ることができます。Shiny - 高さが固定されたスクロール可能なパネル

固定高さのfixedRow内にuiOutput()を格納しようとしましたが、動作しません。

私は

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)

答えて

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) 
+0

これは素晴らしいことです、ありがとうございます! –

+0

高さをページの長さと同じにする方法を知っていますか? –

+0

cssを高さ:100%に変更できます。 –

関連する問題