Closed sjspielman closed 2 years ago
After testing this out, it seems that adding python-tk
to the Docker image is not sufficient for the solution. It seems to be necessary to install this ubuntu dependency to avoid import errors, but a new error now occurs:
_tkinter.TclError: couldn't connect to display "unix:0"
Therefore, even with this dependency installed, there are still errors that matplotlib
triggers because of how graphics generally work within RStudio Server.
A different workaround is possible, however, as described in this stackoverflow post -
you can use
import matplotlib matplotlib.use('agg') import matplotlib.pyplot as plt
if you dont want to use
tkinter
at all.Also dont forget to use %matplotlib inline at the top of your notebook if using one.
EDIT: agg is a different backend like tkinter for matplotlib.
Adding matplotlib.use('agg')
to a python script seems to be the way to go.
Note I tested matplotlib.use('agg')
a Docker image that does NOT have python-tk
installed, and the original tk error returned. Therefore, the solution here requires BOTH: we need to both a) adding the dependency to Docker, and b) setting matplotlib.use('agg')
in the relevant python scripts.
The
tp53_nf1_score
module relies heavily on Python libraries for running the classifier. In addition, this module makes some plots usingmatplotlib
.It turns out this module can only run if it's not being run in interactive mode, e.g. from the rocker IDE, because of a
matplotlib
dependency.. It runs perfectly fine directly from the command line withdocker run
, but not from within a server session. The problem occurs when importingmatplotlib
-According to the internet, this can be pretty easily addressed with a ubuntu installation of
python3-tk
.Therefore, for the
tp53_nf1_score
module to run without errors in an interactive session, we will need to add a line installingpython3-tk
to the Dockerfile.