# Table inside fancyvrb with continuous colorbox?

So I'm trying to insert a table (with an image) in the middle of a \fancyvrb of R code. The \fancyvrb has a \colorbox around it in gray. Is there a way to get all three parts (verbatim pt1, table, verbatim pt2) to be all in the same continuous \colorbox?

I'm willing to forgo the bit that limits the colorbox widths to only the end of the text, instead allowing it to extend to the right margin of the page. But then there's still the problem if no whitespace intbetween the 3 parts

I was thinking maybe I could put everything into \minipage with a gray background, but I was wondering if there was a more elegant solution? Especially since I plan to employ that style many times.

Attempt 1

\usepackage{xcolor}
\colorlet{code}{gray!15!}
\usepackage{verbatim}
\usepackage{fancyvrb}
\newenvironment{cverbatim}
{\SaveVerbatim{cverb}}
{\endSaveVerbatim
\flushleft\fboxrule=0pt\fboxsep=.5em
\colorbox{code}{\BUseVerbatim{cverb}}%
\endflushleft}

\begin{cverbatim}
library("Tidyverse")
library("Quandl")
JPGDP <- Quandl("FRED/JPNRGDPQDSNAQ", type="raw")
\end{cverbatim}
\begin{tabular}{ c  c }\raisebox{-.945\height}
{\includegraphics{r/2.2.1}} & This is text
\end{tabular}
\begin{cverbatim}
p1 <- ggplot(JPGDP, aes(x=DATE, y=VALUE)) +
geom_line()
p1
\end{cverbatim}


Attempt 2

\usepackage{xcolor}
\colorlet{code}{gray!15!}
\usepackage{verbatim}
\usepackage{fancyvrb}
\newenvironment{cverbatim}
{\SaveVerbatim{cverb}}
{\endSaveVerbatim
\flushleft\fboxrule=0pt\fboxsep=.5em
\colorbox{code}{\BUseVerbatim{cverb}}%
\endflushleft}

\begin{cverbatim}
library("Tidyverse")
library("Quandl")
JPGDP <- Quandl("FRED/JPNRGDPQDSNAQ", type="raw")
\end{cverbatim}
\colorbox{\begin{tabular}{ c  c }\raisebox{-.945\height}
{\includegraphics{r/2.2.1}} & This is text
\end{tabular}
\begin{cverbatim}
p1 <- ggplot(JPGDP, aes(x=DATE, y=VALUE)) +
geom_line()
p1
\end{cverbatim}


You could use a simple tcolorbox.

Of course, you will use your image instead of example-image-a.

\documentclass{article}
\usepackage{tikz,lipsum,lmodern}
\usepackage[most]{tcolorbox}
\usepackage{tabularx}
\usepackage{graphbox}

\begin{document}
\begin{tcolorbox}[colback=lightgray!40,colframe=lightgray]
\begin{verbatim}
library("Tidyverse")
library("Quandl")
JPGDP <- Quandl("FRED/JPNRGDPQDSNAQ", type="raw")
\end{verbatim}
\begin{tabularx}{\linewidth}{@{}Xl@{}}
\includegraphics[align=t,width=\linewidth]{example-image-a} & This is text
\end{tabularx}
\begin{verbatim}
p1 <- ggplot(JPGDP, aes(x=DATE, y=VALUE)) +
geom_line()
p1
\end{verbatim}
\end{tcolorbox}
\end{document}