R闪亮的绘图布局UI

3

关于在r Shiny UI中格式化图形位置的快速问题。

到目前为止,我已经在Server.R中制作了一系列直方图,它们在UI中都显示得很完美。唯一的问题是,我希望它们排成2行,每行4个。我的当前代码如下所示,但它给了我3行!顶部有4个图形,第二个有3个图形(还有空间可以容纳第四个),然后最后一行有1个图形...我哪里出错了,是否有更好的方法来布置Shiny中的8个图形?

fluidRow(
   column(12,
       "",
       fluidRow(
         column(3,
                plotOutput("PlotHy")#,

         ),
         column(width = 3,
                plotOutput("PlotMe")),
         column(width = 3,
                plotOutput("PlotEthane")),
         column(width = 3,
                plotOutput("PlotEthylene")),
         column(width = 3,
                plotOutput("PlotCO")),
         column(width = 3,
                plotOutput("PlotCO2")),
         column(width = 3,
                plotOutput("PlotO")),
         column(width = 3,
                plotOutput("PlotN"))
       )
)
),

感谢,詹姆斯。
2个回答

4
只需明确行分隔符即可:

shinyUI(
    fluidPage(

    titlePanel("stack overflow question"),

    fluidRow(
    column(12,
           "",
           fluidRow(
               column(3,
                      plotOutput("PlotHy")),
               column(width = 3,
                      plotOutput("PlotMe")),
               column(width = 3,
                      plotOutput("PlotEthane")),
               column(width = 3,
                      plotOutput("PlotEthylene"))
           ), fluidRow(
               column(width = 3,
                      plotOutput("PlotCO")),
               column(width = 3,
                      plotOutput("PlotCO2")),
               column(width = 3,
                      plotOutput("PlotO")),
               column(width = 3,
                      plotOutput("PlotN"))
           )
    )
)
))

1
一种解决方法是在R本身中完成。
类似这样的东西。
shinyServer(function(input, output, session) {
  output$plot <- renderPlot({
    par(mfrow=c(2,2))
    h1 <- hist(rnorm(100))
    h2 <- hist(rnorm(100))
    h3 <- hist(rnorm(100))
    h4 <- hist(rnorm(100))
  })
})

在 ui.R 中需要添加 plotOutput("plot"),您可以随意放置。

那是一种非常有趣的做法。 - James Willcox

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接