As peanuts were a common concession snack for vaudeville shows, unpopular performers would often find themselves pelted with the easy-to-hurl, edible projectiles, not unlike The Beatles during their 1964 U.S. tour.
Others disagree, in part, with the preceding class-based, rather than racial, claim. They note that in the past, cheap balcony seats were often reserved for, or largely made up of, African American patrons. Thus, since the phrase implies that the opinions expressed by those from the gallery were unsolicited, unwarranted and unhelpful, the phrase also connotes something negative about those giving them, purported to be African Americans.
That said, the Online Etymology Dictionary remains agnostic, as does the Oxford English Dictionary and most etymologists, on whether it truly originally had anything to do with race instead of simply a reference to social class, in this case referring to poor people in general inhabiting these cheap seats.