Consider an open bounded connected Lipschitz polygon or polyhedron $\Omega$, a function $v$ in the Sobolev space $H^1(\Omega)$, and a simplicial mesh $\mathcal{T}_h$ of $\Omega$. We prove the equivalence of two piecewise $p$-polynomial best approximations of $v$ in the $H^1$ seminorm: 1) globally on the whole domain $\Omega$, with the (trace) continuity requirement; 2) locally on each mesh element, without any interelement continuity requirement. The former (global continuous) approximation arises in numerical methods for partial differential equations related to the $H^1(\Omega)$ space, whereas the latter (local discontinuous) approximation is a key quantity in approximation theory. Crucially, we establish $p$-robustness in that the equivalence constant only depends on the mesh shape regularity and the spatial dimension. This improves the recent results of [Found. Comput. Math. {\bf 16} (2016), 723--750] and [Numer. Math. {\bf 135} (2017), 1073--1119], where the equivalence constant was possibly dependent (algebraically or logarithmically) on the underlying polynomial degree. This result has applications in error estimation in finite element methods: in a posteriori analysis of adaptive algorithms, namely to discrete reliability and adaptive tree approximation, and in a priori error analysis, where it allows to obtain fully $h$- and $p$- (mesh-size- and polynomial-degree-) optimal approximation estimates under the minimal Sobolev regularity only requested separately on each mesh element. These two results immediately follow by our construction of an operator from the infinite-dimensional Sobolev space $H^1(\Omega)$ to its finite-dimensional piecewise polynomial subspace that has simultaneously all the following properties: 1) it is defined over the entire $H^1(\Omega)$ and preserves boundary conditions imposed on a part of the boundary of $\Omega$; 2) it is defined locally in a neighborhood of each mesh element; 3) the only information about the given function it uses is its elementwise $H^1(\Omega)$-orthogonal polynomial projection; 4) it is a projector, i.e., it preserves continuous piecewise polynomials; 5) it is locally and $p$-robustly stable in the $H^1(\Omega)$-seminorm; 6) its approximation property is locally and $p$-robustly equivalent to that of the local discontinuous (elementwise $H^1(\Omega)$-orthogonal) projection. Our proofs are complete in two space dimensions, as well as in three space dimensions for a uniform polynomial degree. For a variable $p$ in three space dimensions, we assume the existence of a $p$-stable decomposition. The main tools are $p$-stable decompositions, polynomial extension operators on a simplex and their generalizations to patches of simplices, and the concept of shellability of simplicial complexes with a detour through a barycentric refinement conceived when the complex corresponding to a patch of elements is not shellable, which may potentially happen in three space dimensions.