Consider the following rmarkdown html_notebook example:
---
output: html_notebook
runtime: shiny
---
```{r}
library(ggplot2)
library(shiny)
blank1 <- renderPlot({ ggplot() + labs(title = "Plot 1") })
blank2 <- renderPlot({ ggplot() + labs(title = "Plot 2") })
blank3 <- renderPlot({ ggplot() + labs(title = "Plot 3") })
column(6, blank1, blank2)
column(6, blank3)
```
I would like to have the plots display as:
I have tried a few things including:
fluidRow(
column(6, blank1, blank2),
column(6, blank3)
)
But I have not been able to get Plot 3
to span multiple rows.
Additional Notes (per comments):
cowplot
or patchwork
solution, but I require reactivity from shiny
(e.g. ggplot(aes(x = input$var_select)) + ...
.column()
and/or fluidRow()
to keep of the responsive-design aspects.I was able to solve this by passing the heights into the renderPlot
explicitly. I am still very interested in other solutions:
blank1 <- renderPlot({ ggplot() + labs(title = "Plot 1") }, height = 200)
blank2 <- renderPlot({ ggplot() + labs(title = "Plot 2") }, height = 200)
blank3 <- renderPlot({ ggplot() + labs(title = "Plot 3") }, height = 400)
fluidRow(
column(6, fluidRow(blank1), fluidRow(blank2)),
column(6, fluidRow(blank3))
)
It's not perfect from a responsive design approach, but it'll work.
You could try something like the following which sets the margins on the plot and columns to 0 and sets the heights of plot 3 to be twice that of plots 1 and 2.
---
output: html_notebook
runtime: shiny
---
<!-- break between code folding button and fluid layout -->
<br>
```{r echo=FALSE, message=FALSE}
library(ggplot2)
library(shiny)
# create the plots telling ggplot to use 0 margins
p1 <- ggplot() +
theme(plot.margin = unit(c(0,0,0,0), "cm"),
panel.background=element_rect(fill = "lightgreen"))
p2 <- ggplot() +
theme(plot.margin = unit(c(0,0,0,0), "cm"),
panel.background=element_rect(fill = "lightblue"))
p3 <- ggplot() +
theme(plot.margin = unit(c(0,0,0,0), "cm"),
panel.background=element_rect(fill = "orange"))
# Set the heights in renderPlot so that plot 3 is twice the height
# of the other 2 plots
blank1 <- renderPlot({p1}, height=200)
blank2 <- renderPlot({p2}, height=200)
blank3 <- renderPlot({p3}, height=400)
# Tell the fluid layout to set padding and margin to 0 for the column divs
fluidPage(
fluidRow(
column(6, blank1, blank2, offset=0, style='padding:0px;margin:0px;'),
column(6, blank3, offset=0, style='padding:0px;margin:0px;')
)
)
```
Which results in the following:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With