Coming soon: We’re working on a brand new, revamped Community experience. Want to receive updates? Sign up now!
In a python notebook, I have succeeded in importing and using the seaborn library (based on matplotlib).
However, in a Rmarkdown report, I have the following error ImportError: No module named Tkinter.
How to use seaborn in a Rmarkdown report?
The seaborn python library is indeed using matplotlib. This library contains multiple backends that are not necessarily installed or configured. When loading seaborn, it will try to load the default backend based on TCL/TK (UI framework) which is bundled in the Tkinter python package.
You need to use matplotlib.use("Agg") (or any other properly configured backend) before importing seaborn in order to force matplotlib to use the correct backend. For information, the Agg backend only computes the plots without displaying them.
In notebooks, the magic first line %pylab inline will trigger this method in order to use a backend that sends the output as HTML to the notebook.