Ab initio simulation of charged slabs at constant chemical potential