2016-11-18 114 views
1

我想在兩行兩列布局中放置四個圖。下面的代碼返回兩列一列。如何添加第二列?R由兩列閃亮的兩行

任何幫助表示讚賞。

ui <- shinyUI(
       fluidRow(
         column(6, 
           plotOutput(outputId = "hist1") 
         ), 
         column(6, 
           plotOutput(outputId = "hist2") 
         ) 
       ) 
) 

    server <- function(input,output){ 
      output$hist1 <- renderPlot({ 
        hist(rnorm(100,50,5)) 
      }) 
      output$hist2 <- renderPlot({ 
        hist(rnorm(100,75,5)) 
      }) 
      output$hist3 <- renderPlot({ 
        hist(rnorm(100,100,5)) 
      }) 
      output$hist4 <- renderPlot({ 
        hist(rnorm(100,125,5)) 
      }) 
    } 

    runApp(list(ui = ui, server = server)) 
+0

變化'shinyUI(fluidRow(...))''來shinyUI(fluidPage(fluidRow(...)))' – brittenb

+0

真棒,僅此而已。謝謝。 – Murray

回答

0

從brittenb回答評論:fluidPage()需要添加。

ui <- shinyUI(
     fluidPage(
       fluidRow(
         column(6, 
           plotOutput(outputId = "hist1") 
         ), 
         column(6, 
           plotOutput(outputId = "hist2") 
         ) 
       ), 
       fluidRow(
         column(6, 
           plotOutput(outputId = "hist3") 
         ), 
         column(6, 
           plotOutput(outputId = "hist4") 
         ) 
       ) 
     ) 
) 

server <- function(input,output){ 
     output$hist1 <- renderPlot({ 
       hist(rnorm(100,50,5)) 
     }) 
     output$hist2 <- renderPlot({ 
       hist(rnorm(100,75,5)) 
     }) 
     output$hist3 <- renderPlot({ 
       hist(rnorm(100,100,5)) 
     }) 
     output$hist4 <- renderPlot({ 
       hist(rnorm(100,125,5)) 
     }) 
} 

runApp(list(ui = ui, server = server))