docker-stacks
docker-stacks copied to clipboard
Removing inkscape package from the minimal-notebook
Describe your changes
Removing inkscape package from the minimal-notebook as suggested by @benz0li in this issue.
Checklist (especially for first-time contributors)
- [x ] I have performed a self-review of my code
- [ x] If it is a core feature, I have added thorough tests
- [x ] I will try not to use force-push to make the review process easier for reviewers
- [ x] I have updated the documentation for significant changes
@Bidek56 For the r-notebook and the datascience-notebook you need to create file /opt/conda/lib/R/etc/Rprofile.site and add either
options(jupyter.plot_mimetypes = c('text/plain', 'image/svg+xml', 'application/pdf'))
or
options(jupyter.plot_mimetypes = c('text/plain', 'image/png', 'image/jpeg', 'image/svg+xml', 'application/pdf'))
depending on how many different formats the notebook file (.ipynb) should include.
Any reason to use /opt/conda/lib/R/etc/Rprofile.site instead of ~/.Rprofile? Thx
I do not know much about R but based on this article we can set the plot_mimetypes right in the code. Why would we want to set them globally for all users? Thx
Why would we want to set them globally for all users? Thx
Setting c.InlineBackend.figure_formats = {"png", "jpeg", "svg", "pdf"} in jupyter_server_config.py sets it globally for the Python kernel (IPython).
Setting options(jupyter.plot_mimetypes = c('text/plain', 'image/png', 'image/jpeg', 'image/svg+xml', 'application/pdf')) in /opt/conda/lib/R/etc/Rprofile.site sets it globally for the R kernel (IRkernel).
I am only using c.InlineBackend.figure_formats = {"svg", "pdf"} and options(jupyter.plot_mimetypes = c('text/plain', 'image/svg+xml', 'application/pdf')); no need for png and jpeg.
ℹ️ Every format specified is stored in the notebook file (.ipynb).
Why set these at all? Why not add a documentation line showing users how to add this line to their notebook: options(jupyter.plot_mimetypes = "image/svg+xml")
Why set these at all? Why not add a documentation line showing users how to add this line to their notebook:
options(jupyter.plot_mimetypes = "image/svg+xml")
Removing inkscape without setting these globally will result in errors by default. That should not be the case.
It must work with the default settings.
- I don't like copy-pasting the profile file. I suggest we add it to
minimal-notebook.
Are you saying that you are OK with adding /opt/conda/lib/R/etc/Rprofile.site, ~/.Rprofile or neither? Thx
Why set these at all? Why not add a documentation line showing users how to add this line to their notebook:
options(jupyter.plot_mimetypes = "image/svg+xml")Removing
inkscapewithout setting these globally will result in errors by default. That should not be the case.It must work with the default settings.
This code works without jupyter.plot_mimetypes:
# Create a plot with some normally distributed data
library("ggplot2")
set.seed(42)
n <- 1000
p <- ggplot(data.frame(x = rnorm(n), y = rnorm(n)), aes(x=x, y=y)) +
geom_point(alpha = 0.25, size = 1, colour = "blue") + geom_density2d(colour = "red")
p + ggtitle(sprintf("Mime type = '%s'", getOption("jupyter.plot_mimetypes")))
since by default it seems to be set to image/png and application/pdf according to the docs
Can you please share a test case or code sample where it would fail without jupyter.plot_mimetypes? Thx
- I don't like copy-pasting the profile file. I suggest we add it to
minimal-notebook.Are you saying that you are OK with adding
/opt/conda/lib/R/etc/Rprofile.site,~/.Rprofileor neither? Thx
Yes, I'm ok with both options. I prefer /opt/conda/ version, it is unlikely to mess with the user mounts.
Why set these at all? Why not add a documentation line showing users how to add this line to their notebook:
options(jupyter.plot_mimetypes = "image/svg+xml")Removing
inkscapewithout setting these globally will result in errors by default. That should not be the case. It must work with the default settings.This code works without
jupyter.plot_mimetypes:# Create a plot with some normally distributed data library("ggplot2") set.seed(42) n <- 1000 p <- ggplot(data.frame(x = rnorm(n), y = rnorm(n)), aes(x=x, y=y)) + geom_point(alpha = 0.25, size = 1, colour = "blue") + geom_density2d(colour = "red") p + ggtitle(sprintf("Mime type = '%s'", getOption("jupyter.plot_mimetypes")))since by default it seems to be set to
image/png and application/pdfaccording to the docs Can you please share a test case or code sample where it would fail withoutjupyter.plot_mimetypes? Thx
Unfortunately, I can't help with the example here. @benz0li maybe you could provide one?
The default for IPython is definitively c.InlineBackend.figure_formats = {"png"} only – plus text/plain, the non-removable default for IPython.
Tested with jupyter/scipy-notebook and
import numpy as np
import matplotlib.pyplot as plt
r = np.arange(0, 2, 0.01)
theta = 2 * np.pi * r
fig, ax = plt.subplots(
subplot_kw = {'projection': 'polar'}
)
ax.plot(theta, r)
ax.set_rticks([0.5, 1, 1.5, 2])
ax.grid(True)
plt.show()

ℹ️ Image size: 277 x 269 pixels, Image DPI: 72 pixels/inch
(Retina would be Image size: 555 x 538 pixels, Image DPI: 144 pixels/inch)
Notebook file: No application/pdf in data; "text/plain": ["<Figure size 432x288 with 1 Axes>"]
The default for IRkernel is jupyter.plot_mimetypes = c('text/plain', 'image/png') with jupyter.plot_scale = 2.
Tested with jupyter/r-notebook and
library(ggplot2)
ggplot(airquality, aes(Temp, Ozone)) +
geom_point() +
geom_smooth(method = "loess"
)

ℹ️ Image size: 840 x 840 pixels, Image DPI: 120 pixels/inch
(Due to jupyter.plot_scale = 2 displayed as 480 x 480 pixels, 240 pixels/inch [aka retina] in JupyterLab)
getOption("jupyter.plot_mimetypes")
'text/plain' 'image/png'
getOption("jupyter.plot_scale")
2
Notebook file: No application/pdf in data; "text/plain": ["plot without title"]
Hope this helps in understanding the current IPython and IRkernel defaults.
And as mentioned before: IJulia is a whole different story...
What's the status of this PR?
What's the status of this PR?
I am trying to create tests as per your request but unfortunately I do not know enough about it.
@benz0li @mathbunnyru I have added basic R tests, unfortunately I do not know enough about ggplot2 to add more advance tests. Feel free to add more sophisticated tests or share them so I can add them. Thanks
Could you please remove code duplication as well?
Which code duplication? In the tests?
The test file, Rprofile.site config file and some lines in Dockerfiles.
They are used in different stacks, how would you suggest we re-use them across multiple stacks?
They are used in different stacks, how would you suggest we re-use them across multiple stacks?
As we discussed above, for the config file, let's put it to minimal-notebook. With the test file, just create a test file somewhere with all the code and then import then create two small files in the notebook test folders importing this file content. I think this will work well. Or, put the code in one of two test files and import it in another one.
They are used in different stacks, how would you suggest we re-use them across multiple stacks?
As we discussed above, for the config file, let's put it to minimal-notebook. With the test file, just create a test file somewhere with all the code and then import then create two small files in the notebook test folders importing this file content. I think this will work well. Or, put the code in one of two test files and import it in another one.
The jupyter_server_config.py config file is in base-notebook, why would we move it to minimal?
Rprofile.site belongs to datascience-notebook and r-notebook so it does not make senses to move to move to minimal, what I am missing here? Thx
Sorry for not being clear.
I propose the following:
jupyter_server_config.pystays in the same place - I do not propose to change it's location.Rprofile.siteshould be inminimal-notebook. There are 2 good reasons for this - code duplication and also that this change might break the R users who for whatever reason decided to have their images based onminimal-notebook. This way we will try not to break these users.minetypes_R.ipynbandtest_R_notebook.pyshould not be duplicated as well - I described how we can avoid the duplication quite easily.
With the current changes, IPython and IRkernel are not in sync regarding figure formats/plot mimetypes.
Either reduce c.InlineBackend.figure_formats to {"svg", "pdf"} or extend jupyter.plot_mimetypes to c('text/plain', 'image/png', 'image/jpeg', 'image/svg+xml', 'application/pdf'). 👉 Either https://github.com/jupyter/docker-stacks/pull/1765#issuecomment-1209768706 or https://github.com/jupyter/docker-stacks/pull/1765#issuecomment-1209773517.
ℹ️ Every format specified is stored in the notebook file (.ipynb).