When Gandalf first makes his appearance in The Lord of the Rings, the Hobbits of the Shire clearly have a history with the wandering wizard. The children dance and cheer around his fireworks while others scowl as Frodo says, "You have officially been declared a disturber of the peace." While this was certainly true, most Hobbits did respect Gandalf, as he helped save the Shire many hundreds of years prior.
Gandalf gained his reputation after The Hobbit, as he showed up in the peaceful Shire with Dwarves and convinced Bilbo to leave for a year -- leaving the far-from-adventurous Hobbits overwhelmed by his presence. Yet despite that, he was still known for appearing sporadically to display his fireworks and bring joy to the realm, and the continued love for the wizard all stemmed from one eventful visit.
Gandalf Rescued the Hobbits
Mid-way through the Third Age of Middle-earth (1000 years before The Lord of the Rings), there was a brief era of peace in the world. A defeated and broken Sauron was almost discovered by the wizards, and so he fled into the east and remained hidden for 400 years while he regained his strength. And it was during this peaceful time that Gandalf wandered Middle-earth to meet as many people as he could, which eventually led him to the secluded Shire. Yet it was a simple visit, where he befriended the Hobbits and went on his merry way.
However, soon after this, a deadly winter spread across the world and caused a plight for many. Named the Long Winter, snowfall covered the land for over half a year, affecting almost every town and city -- including the Shire. Because of how separated they were from the rest of civilization, the Hobbits faced the cold alone and succumbed to a deadly famine. The lives of many Hobbits were lost, yet far more were saved in the end, as Gandalf appeared in their desperate hour and used his magics to provide food, warmth and shelter for all.
Gandalf Grew Fond of Hobbits
As Gandalf saved the Shire, he grew an admiration for the Hobbits. Despite their suffering, he witnessed them helping one another and noticed their courage through these harsh times. He eventually had to leave, but his time there had convinced him to return regularly to check up on the Hobbits and help spread joy.
Most notably, Gandalf would return for Midsummer-eve festivals hosted by the Took family, where he showed off his impressive fireworks and told stories of Middle-earth. Although, his tales of adventure somewhat backfired, as Bilbo claimed he was "responsible for so many quiet lads and lasses going off into the blue for mad adventures." And thus, Gandalf's reputation with the Hobbits began to dwindle.
Nevertheless, Gandalf was one of the few powerful people in Middle-earth who actually cared about the Shire, so most still had a fondness for him. And in the end, while Gandalf may have saved the Hobbits, it was the Hobbits who would eventually save him and the entirety of Middle-earth in The Lord of the Rings.