Skip to content
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

Nicer display of pandas dataframes in nbsphinx #182

Closed
gansanay opened this issue Apr 19, 2018 · 10 comments
Closed

Nicer display of pandas dataframes in nbsphinx #182

gansanay opened this issue Apr 19, 2018 · 10 comments

Comments

@gansanay
Copy link

Hi,

I may have missed something but... I can't get pandas dataframes to display in nbsphinx generated docs as nicely as they display in jupyter notebook. I get an ugly large font in an ugly black and white table.

Is it just a CSS issue?

Regards,
Guillaume

@mgeier
Copy link
Member

mgeier commented Apr 19, 2018

Can you please provide an example notebook and screenshots for the "nice" and "ugly" cases? Please also provide a screenshot how it looks when using nbconvert.

@gansanay
Copy link
Author

gansanay commented Apr 19, 2018

Of course. This is "nice":

image

(I am using a dark theme in jupyter, I, don't expect the result to be dark but to look as in the light, vanilla theme.)

This is "ugly":

image

Downloading from jupyter notebook as HTML (nbconvert) leads to the "nice" version. This download is made on my laptop while doc generation is done in a container. Are there package dependencies other than listed in nbsphinx documentation that could explain this behaviour?

Sample notebook: https://gist.github.com/gansanay/34363886efeb3e7c958a281811c14822

@mgeier
Copy link
Member

mgeier commented Apr 19, 2018

Interestingly, when calling nbconvert directly, the result looks more like the "ugly" version.

I think this is only a matter of which CSS is included.

You can add whatever CSS you like to your Sphinx configuration.

Or, if you think some CSS should be added directly to nbsphinx, feel free to make a PR for it.
But I think it makes more sense to first discuss this in the context of nbconvert, then nbsphinx can simply take the CSS from there.

@mgeier
Copy link
Member

mgeier commented Jun 18, 2018

@gansanay Were you able to get "nice" dataframes in the end?

@eotp
Copy link

eotp commented Jun 28, 2018

I have the same issue. Looking here I found that this behavior is related to nbconvert versioning.

By using nbconvert (version 5.3.1) directly with <link rel="stylesheet" href="https://cdn.jupyter.org/notebook/5.1.0/style/style.min.css"> in a Raw NBConvert type cell (as suggested here ) works well; I get a nicely rendered dataframe in the html output. However, using nbsphinx on the same notebook still gives the old ("ugly") rendering. :-(

I even tried to provide a custum .css file (as shown here), using https://cdn.jupyter.org/notebook/5.1.0/style/style.min.css; this did not work either.

@mgeier
Copy link
Member

mgeier commented Jun 28, 2018

You should be able to load the CSS file in your conf.py with

def setup(app):
    app.add_stylesheet(
        'https://cdn.jupyter.org/notebook/5.1.0/style/style.min.css')

In the upcoming Sphinx 1.8.0 release, this can also be done with

html_css_files = ['https://cdn.jupyter.org/notebook/5.1.0/style/style.min.css']

The bad news, however, is that this doesn't seem to work well with the Sphinx and nbsphinx styling.

If you want to improve the situation, please make a PR that puts a copy of the official Jupyter Notebook CSS (I guess for the dataframe class?) into the CSS_STRING variable.

@PedroRegisPOAR
Copy link

I tried the solutions proposed by @mgeier, but none worked. I dont know how to do some workaround nor help to build a solution.

I tried both versions 5.1.0 and 5.4.0 :

html_css_files = ['https://cdn.jupyter.org/notebook/5.1.0/style/style.min.css']

and

html_css_files = ['https://cdn.jupyter.org/notebook/5.1.0/style/style.min.css']

and, both of this too:

def setup(app):
    app.add_stylesheet(
        'https://cdn.jupyter.org/notebook/5.1.0/style/style.min.css')

and

def setup(app):
    app.add_stylesheet(
        'https://cdn.jupyter.org/notebook/5.4.0/style/style.min.css')

This setup function have to be invoked? I just pasted it in the conf.py file.

The results of use nbconvert and nbsphinx are bellow:

nbconvert:
nbconvert-croped

nbsphinx:
nbsphinx-croped

Another stuff that I noticed were that the colors of many things, import line, strings, and numbers are different too. I guess that it is because the css problem too?

The versions of the libraries that I am using:
pandoc 1.17.2

Sphinx==1.8.1
nbsphinx==0.3.5
jupyter==1.0.0
pandas==0.23.4
nbconvert==5.4.0

@mgeier
Copy link
Member

mgeier commented Oct 31, 2018

I've added some CSS definitions in #228, can you please check if that works for you?

If you find some missing CSS definitions, please tell me.

@mgeier mgeier closed this as completed in 5cca4d2 Nov 4, 2018
@PedroRegisPOAR
Copy link

Sorry for the late answer. I tested now and the issue still happening.

How do you test that you have solved the problem?

How can I help you find why I still face the issue?

I use Docker and for help to find where the problem is I have put every thing in a github repository to try help you figure out why the problem still happening.

@mgeier
Copy link
Member

mgeier commented Nov 8, 2018

@PedroRegisPOAR Have you used the master branch? Please note that the changes from #228 are not yet in a released version of nbsphinx.

You should try to install nbsphinx from the Git repository, as described in CONTRIBUTING.rst, or you can install it with pip like this:

python3 -m pip install git+https://github.com/spatialaudio/nbsphinx.git@master

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants