Let $k$ be a field and take $$R=\{(a_i)\in\prod\limits_{i\in\mathbb{N}}k[t]|a_i(0)=a_j(0)\text{ for all }i,j\}$$$$R=\{(a_i)\in\prod\limits_{i\in\mathbb{N}}k[t]\mid a_i(0)=a_j(0)\text{ for all }i,j\}$$
An idempotent in this ring has to be sent to $0$ or $1$ under the map $R\xrightarrow{(a_i)\mapsto a_i(0)}k$ hence has to be equal to $(0,0,...)$ or $(1,1,..)$. However, if we invert $r=(t,t,t,..)$ then each of the elements $(0,\dots,0,t,0,\dots)r^{-1}$ gives an idempotent in the localization.
Geometrically, this is analogous (but is not exactly equivalent as taking spectrum does not take infinite products to disjoint unions) to gluing infinitely many affine lines by their origins to get something connected that splits into infinitely many connected components after removing the origin.