首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使光泽和gridExtra巧妙地工作?

如何使光泽和gridExtra巧妙地工作?
EN

Stack Overflow用户
提问于 2018-05-29 08:11:43
回答 1查看 1.3K关注 0票数 4

我使用using,希望在gridExtra的帮助下,将几个图形并排放置。

有一个情节(没有gridExtra)运行得很好:

代码语言:javascript
复制
library(shiny)
library(plotly)

u <- fluidPage(plotlyOutput(outputId = "myplots"))

s <- function(input, output) {
  pt1 <- reactive({
    ggplotly(qplot(42))
  })

  output$myplots <- renderPlotly({
    pt1()
  })
}

shinyApp(u, s)

现在,当我试图通过gridExtra再添加一个情节时,它拒绝工作:

代码语言:javascript
复制
library(shiny)
library(plotly)
library(gridExtra)

u <- fluidPage(plotlyOutput(
  outputId = "myplots"
))

s <- function(input, output){
  pt1 <- reactive({
    ggplotly(qplot(42))
  })

  pt2 <- reactive({
    ggplotly(qplot(57))
  })

  output$myplots <- renderPlotly({
    grid.arrange(pt1(), pt2(),
                 widths = c(1, 1),
                 ncol = 2)
  })
}

shinyApp(u, s)

给我

gList中的错误:"gList“中只允许”grobs“

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-05-29 09:23:17

与其使用grid.arrange将许多图传递给单个plotlyOutput,不如设置您的ui以接受几个图,然后单独传递它们。例如,您的ui和服务器可能如下所示

请注意,像这样定义列使用Bootstrap主题化,这意味着宽度需要增加到12。

代码语言:javascript
复制
library(shiny)
library(plotly)
library(gridExtra)

u <- fluidPage(
  fluidRow(
    column(6, 
           plotlyOutput("pt1")),
    column(6, 
           plotlyOutput("pt2"))
  )
)

s <- function(input, output){
  output$pt1 <- renderPlotly({
    ggplotly(qplot(42))
  })

  output$pt2 <- renderPlotly({
    ggplotly(qplot(57))
  })

}

shinyApp(u, s)
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50579412

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档