我使用using,希望在gridExtra的帮助下,将几个图形并排放置。
有一个情节(没有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)现在,当我试图通过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)给我
gList中的错误:"gList“中只允许”grobs“
发布于 2018-05-29 09:23:17
与其使用grid.arrange将许多图传递给单个plotlyOutput,不如设置您的ui以接受几个图,然后单独传递它们。例如,您的ui和服务器可能如下所示
请注意,像这样定义列使用Bootstrap主题化,这意味着宽度需要增加到12。
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)https://stackoverflow.com/questions/50579412
复制相似问题