'Plotly figure not showing with IPython

I'm trying out plotly express by pasting the official example in an IPython console.

requirements.txt

ipython
plotly
pandas

Run the below

import plotly.express as px

if __name__ == "__main__":
    import IPython; IPython.embed(using=False)

Paste this:

In [1]:     df = px.data.gapminder().query("country=='Canada'")
   ...:     fig = px.line(df, x="year", y="lifeExp", title='Life expectancy in Canada')
   ...:     fig.show()
   ...: 

In [2]: 

Nothing happens. It works fine (a browser page opens up) if I just run the whole thing as a script without IPython. However during development I would rather be able to play around.

Any ideas why this isn't working?

(Posted this question also on their community page)



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source