How to display a plot next to a table (word export) ?

dear all,
I'm trying to generate a word document containing a table (flextable::regulartable) next to a plot from a shiny app.
Does someone have an idea?
Thanks !

Here is the wanted result:

.

library(flextable)
library(dplyr)
df<-data.frame(c("A", "B"), c(1, 2))
colnames(df)<-c("Letters", "Numbers")
df<-df%>%
  regulartable()
plot<-plot(1,1)

r df

1 Like

Hi,

Unfortunately as far as I know layout definition for word documents if quite limited... HTML and PDF have much more flexibility in that regard.

My suggestion would be you combine the table and plot as one figure, then insert it as a whole. This can be easily done with the gridExtra package. Here is an example:

library(gridExtra)
library(ggplot2)

data(iris)

myTable = tableGrob(iris[1:10,])
myPlot = ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width)) + geom_point()

grid.arrange(myTable, myPlot, nrow = 1)


This is an extreamly basic example, but you'll get the idea :slight_smile: There is a lot of online information on getting good layouts and editing tables.

Hope this helps,
PJ

1 Like

Thanks a lot for your response,
I had already seen this solution but unfortunatly, the table isn't editable in the word.
best regards !
Ben

Hi,

I agree, it's not a great solution, because having a table as an image limits its usability a lot, but you know how difficult it is in word (even manually) to align two pictures or table and picture on the same row without it jumping around ...

One other idea would be you force the document to have two columns (if that's even possible, maybe through a template) and have each in one column. I found a post where they managed it for powerpoint:

Good luck, keep me posted!
PJ

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.