如何在闪亮的r中并排放置多个地块?

你可以吗

在mainpanel中,我尝试通过Fluidrow处理此问题。但是,我的情节之一是可选的,以便用户显示或不显示。当用户单击按钮时,第二个图出现在第一个图的下方。

   fluidRow(
      column(2, align="right",
             plotOutput(outputId = "plotgraph1", width  = "500px",height = "400px"),  
             plotOutput(outputId = "plotgraph2", width  = "500px",height = "400px")
      ))

我玩过“ align”和“ widths”,但是什么都没有改变。

迈克·怀斯

因此,这是几年后的事,尽管其他答案(包括我的答案)仍然有效,但我不建议今天采用这种方式。今天,我将使用摊开来grid.arrangegridExtra包。

  • 它允许任意数量的绘图,并且可以将它们布置在类似网格棋盘格的布局中。(我误以为splitLayout只有两个人工作)。
  • 它具有更多的自定义可能性(您可以指定行,列,页眉,页脚,填充等)
  • 最终,即使对于两个图,它最终也更易于使用,因为在用户界面中的布局非常挑剔-当屏幕尺寸改变时,很难预测Bootstrap将对您的元素进行什么处理。
  • 由于这个问题吸引了大量访问量,因此我认为应该在此处提出更多选择。

cowplot软件包也值得研究,它提供了类似的功能,但是我并不那么熟悉。

这是一个闪亮的小程序,它表明:

library(shiny)
library(ggplot2)
library(gridExtra)

u <- shinyUI(fluidPage(
  titlePanel("title panel"),
  sidebarLayout(position = "left",
      sidebarPanel("sidebar panel",
           checkboxInput("donum1", "Make #1 plot", value = T),
           checkboxInput("donum2", "Make #2 plot", value = F),
           checkboxInput("donum3", "Make #3 plot", value = F),
           sliderInput("wt1","Weight 1",min=1,max=10,value=1),
           sliderInput("wt2","Weight 2",min=1,max=10,value=1),
           sliderInput("wt3","Weight 3",min=1,max=10,value=1)
      ),
      mainPanel("main panel",
          column(6,plotOutput(outputId="plotgraph", width="500px",height="400px"))
))))

s <- shinyServer(function(input, output) 
{
  set.seed(123)
  pt1 <- reactive({
    if (!input$donum1) return(NULL)
    qplot(rnorm(500),fill=I("red"),binwidth=0.2,main="plotgraph1")
    })
  pt2 <- reactive({
    if (!input$donum2) return(NULL)
    qplot(rnorm(500),fill=I("blue"),binwidth=0.2,main="plotgraph2")
  })
  pt3 <- reactive({
    if (!input$donum3) return(NULL)
    qplot(rnorm(500),fill=I("green"),binwidth=0.2,main="plotgraph3")
  })
  output$plotgraph = renderPlot({
    ptlist <- list(pt1(),pt2(),pt3())
    wtlist <- c(input$wt1,input$wt2,input$wt3)
    # remove the null plots from ptlist and wtlist
    to_delete <- !sapply(ptlist,is.null)
    ptlist <- ptlist[to_delete] 
    wtlist <- wtlist[to_delete]
    if (length(ptlist)==0) return(NULL)

    grid.arrange(grobs=ptlist,widths=wtlist,ncol=length(ptlist))
  })
})
shinyApp(u,s)

屈服:

在此处输入图片说明

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章