2017-05-24 1 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 %로 변경할 수 있습니다. –

관련 문제