Rigorous derivation of the Whitham equations from the water waves equations in the shallow water regime