2017-05-24 5 views
0

Ich befolge ein glänzendes Beispiel, um mehrere Plots in einem uiOutput zu plotten. Ich hätte gerne eine Tafel (richtiges Wort?), Die diese Plots enthält, die eine feste Höhe haben, aber erlauben Scrollen, um die Plots jenseits dieser Höhe zu sehen.Shiny - Scrollbares Panel mit fester Höhe

Ich habe versucht, die uiOutput() innerhalb einer FixedRow mit einer festen Höhe, aber es funktioniert nicht.

Ich habe den Code unten

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)
enthalten

Antwort

1

Eine Option ist CSS zu verwenden. Es kann ein wenig hantieren, um alles so zu positionieren, wie Sie es möchten. Hier ist ein schnelles Beispiel:

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

Das funktioniert super, danke! –

+0

Wissen Sie, wie ich die Höhe der Seitenlänge anpassen könnte? –

+0

Sie können die CSS in Höhe ändern: 100% –

Verwandte Themen