1

Using Quarto Markdown in RStudio, I'm trying to position a figure (ggplot2 barplot) to the right hand side of a table (reactable). When I render the page (to html), the figure is displaying to the right of the code and not to the right of my table underneath the code. This is not the case in the Quarto example given here.

Here is a minimal example of my code

```{r, echo=TRUE, results='hold'}
#| fig-column: margin

library(reactable)
reactable(iris)

library(ggplot2)
ggplot(iris, aes(x=Sepal.Length, y=Species)) + 
        geom_bar(stat = "identity")

```

Any ideas as to why my figure is not displaying to the right of the table itself? I would like this to be the case because if I decide to collapse or open my code, I want both the figure and the table to move (up and down) with that event. I don't want this event to result in the table moving up and down and the figure staying to the right of the code.

shafee
  • 15,566
  • 3
  • 19
  • 47
Beatdown
  • 187
  • 2
  • 7
  • 20

1 Answers1

3

It's happening because in this current quarto version (‘1.0.38’), interactive tables (e.g. reactable, DT) are not treated as Tables and are considered more like figures.

Quoting from this github issue

DT tables are part of interactive tables, and they are specific HTML widgets and not tables per-se (not Markdown tables, nor HTML tables)

See these related Github issues/discussion #782, #628, #1084.

But as an alternative, you can create similar representation with column: screen-inset-right and layout chunk options.


---
title: "margin figure"
format: html
---

## Quarto


```{r}
#| label: multiple_output
#| echo: true
#| column: screen-inset-right
#| fig-height: 8
#| layout: "[75, 25]"

library(reactable)
reactable(iris)

library(ggplot2)

ggplot(iris, aes(x=Sepal.Length, y=Species)) + 
        geom_bar(stat = "identity")

```

Which looks like after rendering,

figure_in_margin

shafee
  • 15,566
  • 3
  • 19
  • 47
  • Thank you. This works nicely for the scaled down example here, however, in my real example (still using a ggplot and reactable), they are appearing side by side but switched i.e. the table is in the margin and the plot is in the main, any idea why? thanks for your help. – Beatdown Aug 16 '22 at 10:16
  • In your case, does the code for `reactable` appear before `ggplot` code? – shafee Aug 16 '22 at 10:22
  • No, though I've tried switching them around and it doesn't make any difference to the display – Beatdown Aug 16 '22 at 10:28
  • 1
    My apologies. Switching the order did in fact produce the intended output. I must have made a mistake previously. I will accept your answer, thanks for your help! – Beatdown Aug 16 '22 at 10:41