There are connections, you can find plenty of them on e-podroznik.pl. Most (all?) of them are the same:
Gdańsk Główny (main station) to Lębork by train (regional or Intercity), cost: 16 PLN
Lębork to Łeba by bus (Trede TRANS or Boguś BUS), cost: 12 PLN
It takes 2-3 hours depending on the connection and there's a train leaving Gdańsk. Total price is 28 PLN (...