One who lives among people who commit shirk
A man lives within a community that commits shirk (polytheism) by appealing for help from other than Allah. Is he allowed to pray with them with their leading the prayer? Is it obligatory to abandon them? Is their Shirk considered shirk al-akbar (great and serious act of disbelief by associating other beings with Allah's supremacy)? Is alliance with them treated the same as alliance with true non-believers?
If the condition of those with whom you live is as you mentioned, appealing for help from other than Allah, such as appealing for help from the dead and the non-living or the trees or stones or planets and the like, then they are committing the greatest shirk which causes expulsion from the community and faith of Islam.
It is not allowed to ally with them just as it is not permissible to ally with non-believers. Praying behind them is not valid. It is not allowed to mix socially with them nor to reside amongst them except for the one who calls them to the truth with knowledge, and sees hope that they will accept and that their religious condition will become correct due to his efforts.
Otherwise, it becomes obligatory for him to abandon them and to join a different community in which he can work with on establishing the fundamentals of Islam and its branches and reviving the example of the Prophet (peace be upon him). If he is not able to find the proper community, he should seclude himself from all communities, even if he experiences harshness, as has been related by Huthaifa (may Allah be pleased with him), who said: "The people used to ask the Messenger of Allah (peace be upon him) about goodness. And I used to ask him about evil from fear of falling in it. So I said, O Messenger of Allah, we used to be in ignorance and evil but Allah gave us this goodness, so is there evil after this goodness? He said: «», so I said is their goodness after this evil? He said « », I said: what is its darkness? He said: « », so, I said: is there any evil after that goodness? He said: « », so, I said: O Messenger of Allah describe them to us. He said: « », I said: O Messenger of Allah, what do you command me to do if this happens in my time? He said: « », so, I said: What if there weren’t a community of Muslims nor a leader? He said: « »" (Mutafaqun alayh, lit. agreed upon, i.e. narrated by both Muslim and Bukhari).
Blessings of Allah be upon our Prophet Mohammed, his family and companions.
Sheikh Muhammed Salih Al-Munajjid.