I think it's very important for parents to teach their kids how to behave in different settings, but it's not always the easiest thing to do--and it's something you'll have to remind them of over and over again. One thing that helps for my two boys when they start running around wild somewhere is to remind them that they're not at the playground. I get down to their level and say quietly but sternly, "This is not a playground. This is a restaurant/store/museum, etc. There are people here trying to enjoy their food/shop/work/, etc. We can't run and be loud here, but you can walk along and look at the interesting things/sit in the stroller and read books/sit nicely in your chair and play with playdough, etc." This lets them know that it's not just my expectation but the expectation of the all the people around them in that place. It's also not enough. That talk sets the groundwork for their general understanding that there's a time and place for everything, but it's not always enough for young ones.
There was a time when my oldest was 16 months and I thought I would never be able to take him out of the house until he turned five--at least! He would not stay with me if I let him out of the stroller/cart, and he wouldn't come back when I called him--he'd just run further and faster in the other direction. Not to mention he was also just crazy when he would play with his friends. I finally took a page from Super Nanny and started training him to stay with me and stop when I said to.
Tell your daughter what you expect her to do (stop and wait when you say) and what will happen if she doesn't (have a time out in the stroller or holding hands), then as you're walking along (in a safe, quiet place like a park), let her get a few feet in front of you. Ask her to stop and wait for you. If she does, great. Praise her for good listening/following instructions and move on. In another minute do the same thing. If she does what you ask, reward her with praise for good listening. If she doesn't, strap her in the stroller or hold her hand for two minutes. She may throw a big fit, but hold her tight or keep her in the stroller--it's only two minutes after all. Then remind her of your expectations and the consequences if she doesn't meet them, and tell her she can try again. Wander around the park and keep asking her to stop every couple of minutes until she's really got the hang of it. Then when you take her somewhere else, try it out a time or two when you first get going just to remind her.
You do have to respect the fact that your daughter is active and independent, but those qualities don't need to go unbridled, so you have to work to find a balance. The other day my son was almost buzzing when we got out of the car to go to the book store. I knew I was in for trouble if we walked right in. So I had him run around for a couple of minutes out on the side walk and that took care of his burst of energy. If you see your daughter needs to burn off energy, find ways to do it: hopping in place, running circles around a tree, dancing, shaking out different body parts. In public, just try to find an out of the way spot, and do it just before you begin your outing.
Also, your daughter may be independent, but you are in charge. If you need her to be in the cart so you can do your grocery shopping, tell her in the car that you know she's not crazy about it, but she'll be sitting in the cart so you can get your shopping done quickly and stay out of the way of others. For now that's just the way it is; that's just what you do. If she throws a tantrum you'll have to deal with it, and then you may have to do your shopping in the evenings without her for a while--pointing out that she can't come along until she's ready to listen. If you need her to wear a leash at festivals or other busy and crowded places, that's just what she'll have to learn to do for now. She can sit in the stroller instead--you can let her decide. But make it clear that those are her only two options. You decide what YOU need her to do and if you give her options, they should be options that work for YOU.
Just like teenagers, she earns her freedom when she shows she can handle the responsibility. I think in a way you are expecting too much from her at this point--she can't yet handle the freedom to walk on her own everywhere you go--but maybe you aren't expecting enough either--that she follows the limitations you set based on her age and ability. Figure out what your limits for her need to be for her safety and your sanity and teach her to stick to them. Once she can do that, you can try to give her more freedom, and you'll see her adjust as she matures.
Sorry for the long response. Hope it helps. Good luck!