-
Notifications
You must be signed in to change notification settings - Fork 201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
xarray html reprs hidden #238
Comments
Thanks for opening your first issue here! Engagement like this is essential for open source projects! 🤗 |
do you have a Also it'd help if you can provide a link to a website with this bug / code to reproduce it. |
Hi @choldgraf, I didn't add any tags to that cell. When I use the rtd theme, the xarray.Dataset repr is not hidden. I don't currently have a way to share the webpage, but I am working on that. It is a just a simple notebook in Jupytext percent format, included in my Sphinx docs build using nbsphinx. Sphinx configuration# -- General configuration ---------------------------------------------------
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
"sphinx.ext.napoleon",
"sphinx.ext.autodoc",
"sphinx.ext.autosummary",
"sphinx_rtd_theme",
"nbsphinx",
"sphinxcontrib.bibtex",
"myst_parser", # automatically used to parse .md files
]
# Make nbsphinx detect Jupytext files
nbsphinx_custom_formats = {
".py": ["jupytext.reads", {"fmt": "py:percent"}],
}
# Figure quality
nbsphinx_execute_arguments = [
"--InlineBackend.figure_formats={'svg'}",
# "--InlineBackend.rc={'figure.dpi': 96}",
]
# Add any paths that contain templates here, relative to this directory.
templates_path = ["_templates"]
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ["_build", "conf.py", "Thumbs.db", ".DS_Store"] Jupytext script that goes with the image I posted# %%
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import xarray as xr
import crt1d as crt
# %matplotlib inline
# %% [markdown]
# ## Run (just once)
# Run the default case (which is loaded automatically when model object is created).
# %%
ms = []
for scheme_ID in crt.solvers.AVAILABLE_SCHEMES.keys(): # run all available
m = crt.Model(scheme_ID, nlayers=60)
m.run()
m.calc_absorption()
ms.append(m)
dsets = [m.to_xr() for m in ms]
# %% [markdown]
# ### Examine default case
#
# Leaf area profile and leaf angle dist, using the plotting methods attached to the `Model` instance.
# %%
...
# %% [markdown]
# ## Datasets and their variables
# %%
dsets[0]
# %%
dsets[0]["zm"] |
I guess I am trying to figure out what you mean by:
How is a "hidden" class being attached to the output? |
It looks like it always has Can see it being set here: Should I raise this issue with xarray? |
hmmmm....so I guess that |
Looks like there is already an open issue: pydata/xarray#4320
|
Most of the xarray folks have little experience with CSS (except maybe @benbovy who wrote html repr), so if you have a suggestion or a fix I'm sure it'll be much appreciated! |
It looks like another side effect of pydata/xarray#4053. We could revert this dirty hack, but then the rendering issues will come back in other Jupyter Front-ends such as Notebook / Lab. I don't really know what to do to solve this unfortunately 😕. |
Hmmm - yeah I mean it seems like the behavior of "not showing up when the |
The 'hidden' attribute is there to prevent showing the html repr when a notebook is not trusted. Jupyter Notebook and Lab do not inject the repr's CSS if that's the case, and without CSS, xarray's html reprs look totally ugly and unusable (like it's still the case in notebooks viewed on GitHub). The 'hidden' attribute of an element should be ignored by browsers if there's a CSS display property defined for that element. We use this as a (weak) trick in xarray to show the repr when the repr's CSS is injected. But in this case, it doesn't work because (I think) bootstrap 4 explicitly sets 'display: none' for all elements having the HTML 'hidden' attribute. Maybe there's a way to add in this theme some CSS that supersedes bootstrap's definitions? Probably we could add an extra display option in xarray as a flag to enable/disable this trick, if that could help... |
ohh interesting - so if I understand you:
If so, what is the CSS class that xarray uses, and we can special-case it in the theme (probably we'll want to do this in the pydata theme, since I could see this issue popping up in other pydata projects). |
Can confirm Bootstrap 4 sets https://github.com/twbs/bootstrap/blob/v4.5.3/dist/css/bootstrap.css#L353-L355 |
Yes that's correct, although I admit it's very confusing and I don't really like it (https://html.spec.whatwg.org/multipage/interaction.html#the-hidden-attribute). I think all you need here is to add the line below in this theme's CSS (given that it is injected after Bootstrap's CSS) .xr-wrap { display: block !important } |
ok cool, I am happy to special-case but - longer term I agree that this is very hacky 😅 |
Yeah longer term it would be great if we could somehow inject custom CSS once and safely in notebooks (if that's possible). Right now the whole CSS is embedded with every repr shown in output cells, which is not ideal either. |
hey whatever works :-) |
Now that Jupyterlab 3 makes easier the installation of extensions with pip/conda, I'm wondering if we could eventually ship a lightweight extension with xarray... |
that's a really interesting idea - I think this would totally work if that pattern becomes a community standard across other UIs (and if you particularly care about other UIs as well, like colab / vscode / etc...and if you don't care about those UIs, then either way yes I think this would be a great use of the new jupyterlab extension mechanism) |
closing this as we should now properly display xarray via the pydata theme, feel free to re-ping here if it doesn't work in the future. Ref: https://pydata-sphinx-theme.readthedocs.io/en/latest/demo/theme-elements.html?highlight=xarray#xarray |
Describe the bug
If I disable
display: none !important
for[hidden]
, they appear properly.I don't have this issue with other themes I have tried, such as the rtd theme.
The text was updated successfully, but these errors were encountered: