R闪亮两行两列

时间:2016-11-18 03:22:39

标签: r shiny

我想在两行两列布局中放置四个图。下面的代码返回两列一列。如何添加第二列?

感谢任何帮助。

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

1 个答案:

答案 0 :(得分: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))