Creating a separate document for the article is the easiest way. It has to be compiled only once and output plus source code can be included in the beamer frame.
But if you prefer to have only one source document which starts the compilation of the article, you can use the following (based on tcolorbox
):

\documentclass{beamer}
\usepackage[skins,listings,raster]{tcolorbox}
\usetheme{Warsaw}
\begin{document}
\begin{frame}[fragile]
\frametitle{\LaTeX{} code}
\begin{tcblisting}{
enhanced,oversize,lower separated=false,
colframe=red!50!black,colback=yellow!10!white,
interior style={top color=yellow!5!white,bottom color=yellow!20!white},
listing side comment,
listing options={style=tcblatex,texcsstyle=*\color{red!70!black}},
pdf comment,
comment style={drop lifted shadow},
compilable listing,
run pdflatex,
raster columns=1}
\documentclass{article}
\usepackage{lipsum}
\title{Sample title}
\author{Sample author}
\date{}
\begin{document}
\maketitle
\section{Sample section}
\lipsum[1-3]
\end{document}
\end{tcblisting}
\end{frame}
\end{document}
Since the compilation of the article has to be started during compilation of the beamer frames, you have to use the -shell-escape
option.
pdflatex -shell-escape mybeamerfile.tex
The example contains just one page. To select e.g. a possible page 3, you could use
comment style={drop lifted shadow,graphics pages={3}}
You can also show more than one page of output, but the size of each will shrink:

\documentclass{beamer}
\usepackage[skins,listings,raster]{tcolorbox}
\usetheme{Warsaw}
\begin{document}
\begin{frame}[fragile]
\frametitle{\LaTeX{} code}
\begin{tcblisting}{
enhanced,oversize,lower separated=false,
colframe=red!50!black,colback=yellow!10!white,
interior style={top color=yellow!5!white,bottom color=yellow!20!white},
listing side comment,sidebyside gap=5mm,
listing options={style=tcblatex,texcsstyle=*\color{red!70!black}},
pdf comment,
comment style={drop small lifted shadow},
compilable listing,
run pdflatex}
\documentclass{article}
\usepackage{lipsum,tikz}
\title{Sample title}
\author{Sample author}
\date{}
\begin{document}
\maketitle
\section{Sample section}
\lipsum[1-12]
\begin{center}
\tikz\shadedraw [shading=ball]
(0,0) circle (3cm);
\end{center}
\end{document}
\end{tcblisting}
\end{frame}
\end{document}
\usepackage{pdfpages}
and\includepdf{filename}
?