Provide means to hide stdout and/or stderr
See original GitHub issueIs your feature request related to a problem? Please describe. It would be desirable to sometimes hide stdout and/or stderr for a final polished report.
For example consider the following code:
import sys
import warnings
warnings.simplefilter(action='ignore', category=Warning)
from plotnine import ggplot, aes, geom_bar
from plotnine.data import mpg
import pandas as pd
# some pseudo-warning from pandas
pd.reset_option('all')
# stderr
sys.stderr.write("This should go away")
print("I guess this will go away as well")
#stuff printed from plots
p = ggplot(mpg) + \
geom_bar(aes(x="class"))
display(p);
This will look like this in jupyterbook:
All elements with an arrow should not be present in the final report.
Using nbconvert it is easy to write a jinja2 template that gets rid of stdout and stderr so, the final result looks like this:
Describe the solution you’d like I would like to have a way to selectively hide stdout and/or stderr from the final report. For example set the cell metata to remove_stdout and/or remove_stderr in a similar way as remove_input.
Describe alternatives you’ve considered I have no idea how to handle this right now, but I would love to hear suggestions.
Additional context The example is minimal for reproducibility, but it illustrates what I would like to remove, the reasons why to remove these from the final report:
stdout:
- as shown in the example some plotting systems (plotnine in this case) produce a printing of the repr of the class as side effect when showing the plot. In this particular case there is the option to use p.draw(); that would hide it, but this doesn’t work together with ipywidgets tabs, so there is the need to hide these things.
- Maybe I would like to have some printings in the notebook as sanity check etc, but leave those out from the final report.
- Some libraries write warnings to stdout and there is no way to get rid of them, look at the pandas example in this case. Again this should not be included in the report.
stderr:
- I don’t have an easy to reproduce example of this, but some libraries do emit warnings in stderr that you cannot remove by filtering warnings out (sqlalchemy-redshift seems to be one of those in my hands right now, spits lots of strange warnings and I cannot get rid of them). So there is the need to hide stderr sometimes as well.
attached: jupyter notebook, html folder produced by jupyterbook, nbconvert template that removes stdout and stderr, html produced by nbconvert.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:13 (6 by maintainers)
Top GitHub Comments
I may be a bit naive, but looking at what you can do with nbconvert, I think there is not much more (useful) to remove or hide besides what jupyter-book already offers + stdout and stderr
Right, sometimes it is not possible: for example with the plotnine example, if you get sys.stdout and direct to something else, and you want to combine with Ipywidgets to produce tabs, then you also loose the plot itself. Stderr maybe is easier, but ideally one would like to show it in the notebook, so that another developer would see the warnings, but hide it from the final report, as non coders consuming reports are not interested in warnings.