问题
In my shiny dashboard, I am currently plotting 1 bar graph above, and 4 pie charts below, as follows:
fluidRow(
column(12, plotOutput("bar1"))),
fluidRow(
column(3, plotOutput("pie")),
column(3, plotOutput("pie2")),
column(3, plotOutput("pie3")),
column(3, plotOutput("pie4")))
How would I go about plotting the bar chart alongside the 4 pie charts, with the pie charts arranged in a square?
Effectively the bar chart would be column(6,...
and all of the pie charts would be column(3,...
but I would need the bar chart to extend to 2 rows so the pie charts are plotted directly beside it.
回答1:
Standard plotOutput
has a height of 400px
plotOutput(outputId, width = "100%", height = "400px", click = NULL,
dblclick = NULL, hover = NULL, hoverDelay = NULL, hoverDelayType = NULL, brush = NULL, clickId = NULL, hoverId = NULL, inline = FALSE)
So you can do the following:
library(shiny)
ui <- fluidPage(
fluidRow(
column(6, plotOutput("bar1",height = "800px")),
column(6,
column(6, plotOutput("pie")),
column(6, plotOutput("pie2")),
column(6, plotOutput("pie3")),
column(6, plotOutput("pie4"))
))
)
server <- function(input, output) {
output$bar1 <- renderPlot({
hist(rnorm(1:100));box();grid()
})
output$pie <- renderPlot({
plot(rnorm(1:100));box();grid()
})
output$pie2 <- renderPlot({
plot(rnorm(1:100));box();grid()
})
output$pie3 <- renderPlot({
plot(rnorm(1:100));box();grid()
})
output$pie4 <- renderPlot({
plot(rnorm(1:100));box();grid()
})
}
shinyApp(ui,server)
来源:https://stackoverflow.com/questions/50003279/r-shiny-layouts