Consider the following two statements of the Savior, which at first may seem contradictory:
3 Nephi 12:16
16 Therefore let your light so shine before this people, that they may see your good works and glorify your Father who is in heaven.
3 Nephi 13:1
1 Verily, verily, I say that I would that ye should do alms unto the poor; but take heed that ye do not your alms before men to be seen of them; otherwise ye have no reward of your Father who is in heaven.
"Let your light shine" seems to expect us to come out of the shadows and allow our good works to be seen by others. The next statement checks our motives--"but take heed that you do not [good works] before men to be seen of them..." (emphasis added).
So, "let your light so shine before this people", but not "to be seen of them". One of my weaknesses is that I like being noticed for the good things I do. It's very easy for me to fall into the trap of doing things to be noticed, not just to do good. How are we to go about balancing these two injunctions? The correct motive was given in the first reference: "...that [this people] may see your good works and glorify your Father who is in heaven."
President Russell M. Nelson gave this helpful advice to the youth:
Anytime you do anything that helps anyone—on either side of the veil—take a step toward making covenants with God...you are helping to gather Israel. It is as simple as that.
So, the answer is simply that we shift our focus on bringing people to God.
Doctrine and Covenants 4:5
5 And faith, hope, charity and love, with an eye single to the glory of God, qualify him for the work.