小编d_w*_*d_w的帖子

如何使plotly与shiny和gridExtra一起工作?

我正在使用 R闪亮,想在 gridExtra 的帮助下并排放置几个 ggplotly 图。

一张图(没有 gridExtra)效果很好:

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)
Run Code Online (Sandbox Code Playgroud)

现在,当我尝试通过 gridExtra 添加另一幅图时,它拒绝工作:

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)
Run Code Online (Sandbox Code Playgroud)

给我

gList 中的错误:“gList”中仅允许“grobs”

r gridextra shiny plotly r-plotly

5
推荐指数
1
解决办法
1567
查看次数

标签 统计

gridextra ×1

plotly ×1

r ×1

r-plotly ×1

shiny ×1