Thanks, Eliphaz, for the date of original invention of the dynamo! In a steam locomotive context the interesting question is how MUCH later did the use of dynamo-powered electric headlights become common on locomotives? I tried to look this up, but neither of the steam locomotive defence/history books I own (Alfred Bruce and Angus Sinclair) seem to have anything about headlights or dynamos.
Looking at Stauffer's "Pennsy Power," I think it MAYbe that the Pennsylvania Railroad didn't start using dynamos and electric headlights until 1900 or so. Their standard mounting (in the 1920s/1930s, say: at the end of the steam era they moved the dynamo to the front) had the dynamo on top of the smoke-box, just aft of the headlight (which was mounted high on the front of the boiler-- top of headlight above top of smokebox). This is very visible in side views. On the other hand, photos of late 19th C power, and even some from the very beginning of the 20th C, show big, boxy, headlights with a "finial" at the top that may be an exhaust outlet for an oil or gas burning light, and do NOT show dynamos behind them.
Sorry I can't be more informative: the books I thought might answer the question didn't. The PRR photos... well, my guess about them is what I have written, but I can't be sure: it's possible that early electric headlights were housed in boxes like the preceding oil or bass ones, and the dynamo might have been mounted somewhere else.