The Constrained RPA Method for Calculating the Hubbard U from First-Principles